Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
60 commits
Select commit Hold shift + click to select a range
bb6a407
add unnamed using flipper template
ltfschoen Jun 10, 2023
231d7ae
wip
ltfschoen Jun 11, 2023
8fdf3bb
wip
ltfschoen Jun 11, 2023
3faf53e
resolve some errors
ltfschoen Jun 11, 2023
e5e7720
fix all errors
ltfschoen Jun 12, 2023
14b04a5
use raw bytes instead of hash type so can access length of block hash
ltfschoen Jun 12, 2023
7d035fe
save and emit entropy of coin1 and coin2
ltfschoen Jun 12, 2023
f1b5c55
wip stuck stubbing blocknumber from ink environment
ltfschoen Jun 13, 2023
56aaa29
use set_block_number from pr to upstream working
ltfschoen Jun 13, 2023
10a08f8
fix contracts using String but already uploaded error
ltfschoen Jun 15, 2023
88782c0
working. allow toggle --skip-dry-run with bulk comment
ltfschoen Jun 15, 2023
aeb12bc
add basic_contract_caller from ink-examples
ltfschoen Jun 15, 2023
ed4290e
add basic_contract_caller all working
ltfschoen Jun 16, 2023
931fe20
remove get message from main contract and do not call it generates error
ltfschoen Jun 16, 2023
4217f6b
restore get method in main contract
ltfschoen Jun 16, 2023
455c222
convert to CreateBuilder and CallBuilder but with error when call via…
ltfschoen Jun 16, 2023
e5f449a
fix basic-contract-caller
ltfschoen Jun 17, 2023
5686da3
call via main but no Builder not support tuple return Decode(Error)
ltfschoen Jun 18, 2023
bf4e6f2
fix Decode(Error) caused by assertion failing since call from contrac…
ltfschoen Jun 18, 2023
3433a89
demo handling errors
ltfschoen Jun 19, 2023
75f5370
fix LangError
ltfschoen Jun 19, 2023
4ae3e63
setup moonbeam MyToken template
ltfschoen Jun 20, 2023
39fcd92
ipsp22
ltfschoen Jun 20, 2023
73750e6
update readme and add ipsp22 script
ltfschoen Jun 21, 2023
768361f
add evm example pending astar response
ltfschoen Jun 22, 2023
e98be60
Merge pull request #17 from ltfschoen/moonbeam
ltfschoen Jun 22, 2023
8887442
update precompile but DeploymentError RandonNumber hit a require or r…
ltfschoen Jun 23, 2023
fd5624c
incorporate feedback from moonbuilders
ltfschoen Jun 23, 2023
d68f6d5
fix so only use randomness after instantiated Randomness
ltfschoen Jun 24, 2023
4962720
try use console log
ltfschoen Jun 24, 2023
2f66366
wip errors due to https://github.com/trufflesuite/truffle/issues/3468…
ltfschoen Jun 24, 2023
4df48da
stuck on error ProviderError 32603 calling requestRandomness
ltfschoen Jun 25, 2023
30db35e
StatusError in tx for requestRandomness
ltfschoen Jun 25, 2023
df8ac88
try change to Websocket endpoint but error Web3WSProviderError: Reque…
ltfschoen Jun 26, 2023
84a6508
MethodNotImplementedError: The method you're trying to call is not im…
ltfschoen Jun 26, 2023
49f7632
timeouts
ltfschoen Jun 26, 2023
2efa2e6
works up to getting requestId but still often get error PollingBlockT…
ltfschoen Jun 26, 2023
6d85e28
tests working enough to generate random number
ltfschoen Jun 27, 2023
5b96de4
update readme
ltfschoen Jun 27, 2023
3b01dd0
add vrf template contracts
ltfschoen Jun 27, 2023
fb3d91f
wip Chainlink VRF Sepolia
ltfschoen Jun 27, 2023
2a2cd51
Uncaught Error: invalid 1st argument: block_number value was not vali…
ltfschoen Jun 27, 2023
dd0d6ab
success deploying chainlink VRF to Sepolia
ltfschoen Jun 27, 2023
f1d3067
Merge pull request #20 from ltfschoen/chainlink
ltfschoen Jun 27, 2023
039630f
trying to interact with vrf to play game
ltfschoen Jun 28, 2023
e8992e4
able to get instance of vrf contract
ltfschoen Jun 28, 2023
3a8541b
fix use of correct alchemy key
ltfschoen Jun 28, 2023
5d3b2c3
fix migration, requires min deposit of 1 eth to not error
ltfschoen Jun 29, 2023
34e8cf5
fix use of alchemy but error when creating chainlink subscription to …
ltfschoen Jul 2, 2023
a7a7971
wait a few blocks before get rolled value for player
ltfschoen Jul 2, 2023
79af150
show current error
ltfschoen Jul 2, 2023
991b0cd
wip
ltfschoen Jul 2, 2023
4da18cf
insufficient funds for gas * price + value
ltfschoen Jul 3, 2023
78c4c52
crashes on requestRandomness. fixes error insufficient funds for intr…
ltfschoen Jul 3, 2023
74eca77
wip
ltfschoen Jul 3, 2023
4e136dc
fix vrf
ltfschoen Jul 5, 2023
5dde11b
wip
ltfschoen Jul 6, 2023
0d6b01a
split flipper from moonbase vrf example
ltfschoen Jul 6, 2023
5f827f9
update readme
ltfschoen Jul 6, 2023
b724f57
rename flipper folder to randomness
ltfschoen Jul 6, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
stuck on error ProviderError 32603 calling requestRandomness
  • Loading branch information
ltfschoen committed Jun 25, 2023
commit 4df48dad78a3c338580423c03bac3efc66f1bf74
3 changes: 3 additions & 0 deletions dapps/evm2/flipper/.env.example
Original file line number Diff line number Diff line change
@@ -1,2 +1,5 @@
# https://faucet.moonbeam.network/
MOONBASE_PRIVATE_KEY='0x'
# https://blastapi.io/
MOONBASE_BLASTAPI_ENDPOINT=''
MOONBASE_BLASTAPI_NETWORK_ID=
5 changes: 5 additions & 0 deletions dapps/evm2/flipper/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,11 @@ Then configure Truffle to connect to it Moonbeam Development `node_modules/.bin/

Preferably use Moonbase Alpha TestNet `node_modules/.bin/truffle migrate --network moonbase` that requires testnet tokens from the faucet https://faucet.moonbeam.network/.

Note: When running tests against Moonbase Alpha TestNet. Disconnect VPN. Try to avoid encountering errors like `Too Many Requests`, `ProviderError`, `ETIMEDOUT`, `32603`, it is important to use a dedicated endpoint that you can get for free here https://blastapi.io/ by creating an account, creating a project, choosing Moonbase Alpha Testnet from their available endpoints and clicking "Activate", and then copying either the RPC endpoint.
Note: I got error `TypeError: Cannot create property 'gasLimit' on string '0x464aff'` when tried using Blastapi WSS endpoint instead of RPC (https) endpoint.

This is important because the public endpoint https://rpc.api.moonbase.moonbeam.network has stricter rate limiting. Ensure that you replace the public Moonbase Alpha endpoint in the truffle-config.js file with the dedicated endpoint.

Run tests
```
truffle test
Expand Down
2 changes: 1 addition & 1 deletion dapps/evm2/flipper/contracts/Flipper.sol
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ contract Flipper {
/// A message that can be called on instantiated contracts.
/// This one flips the value of the stored `bool` from `true`
/// to `false` and vice versa.
function flip() public {
function flip() public payable {
value = !value;
}

Expand Down
2 changes: 1 addition & 1 deletion dapps/evm2/flipper/contracts/lib/RandomNumber.sol
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ contract RandomNumber is RandomnessConsumer {
// The fee can be set to any value as long as it is enough to cover
// the fulfillment costs. Any leftover fees will be refunded to the
// refund address specified in the requestRandomness function below
uint256 public MIN_FEE = FULFILLMENT_GAS_LIMIT * 5 gwei;
uint256 public MIN_FEE = FULFILLMENT_GAS_LIMIT * 5 gwei; // 0.000000001 Ether == 1 gwei
uint32 public VRF_BLOCKS_DELAY;
bytes32 public SALT_PREFIX = "change-me-to-anything";

Expand Down
1 change: 1 addition & 0 deletions dapps/evm2/flipper/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
"version": "1.0.0",
"dependencies": {
"@truffle/hdwallet-provider": "^2.1.12",
"bn.js": "^5.2.1",
"dotenv": "^16.3.1",
"moonbeam-truffle-plugin": "github:PureStake/moonbeam-truffle-plugin",
"truffle": "^5.10.0",
Expand Down
109 changes: 75 additions & 34 deletions dapps/evm2/flipper/test/test_Flipper.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,22 @@
var Web3 = require('web3');
const BN = require('bn.js');
// require('dotenv').config()

// Uses Mocha and Ganache
const Randomness = artifacts.require("../build/contracts/Randomness");
const RandomnessConsumer = artifacts.require("../build/contracts/RandomnessConsumer");
const RandomNumber = artifacts.require("../contracts/lib/RandomNumber");
const Flipper = artifacts.require("../contracts/lib/Flipper");

// let web3 = new Web3(new Web3.providers.WebsocketProvider(process.env.MOONBASE_BLASTAPI_ENDPOINT));
// // when using BlastAPI WSS endpoint I get error `TypeError: Cannot create property 'gasLimit' on string"`
// // https://github.com/web3/web3.js/issues/3573
// console.log('web3.currentProvider: ', web3.currentProvider);
// Randomness.setProvider(new Web3.providers.WebsocketProvider(process.env.MOONBASE_BLASTAPI_ENDPOINT));
// RandomnessConsumer.setProvider(new Web3.providers.WebsocketProvider(process.env.MOONBASE_BLASTAPI_ENDPOINT));
// RandomNumber.setProvider(new Web3.providers.WebsocketProvider(process.env.MOONBASE_BLASTAPI_ENDPOINT));
// Flipper.setProvider(new Web3.providers.WebsocketProvider(process.env.MOONBASE_BLASTAPI_ENDPOINT));

advanceBlock = () => {
return new Promise((resolve, reject) => {
web3.currentProvider.send({
Expand Down Expand Up @@ -31,23 +44,24 @@ contract('Flipper', accounts => {
const requiredDeposit = "1000000000000000000"; // Wei (1 Ether)
const blockTimeout = 1000000;
const initValue = false;
beforeEach(async (done) => {
beforeEach(async () => {
console.log('beforeEach');
randomnessInstance = await Randomness.at("0x0000000000000000000000000000000000000809");
console.log('randomnessInstance.address:', randomnessInstance.address);
// console.log('randomnessInstance.address:', randomnessInstance.address);
RandomnessConsumer.link(randomnessInstance);
RandomNumber.link(randomnessInstance);

// Create contract with 1 Ether (contract must be payable)
randomNumberInstance = await RandomNumber.deployed(); //.new({ from: accounts[0], value: requiredDeposit });
console.log('randomNumberInstance.address:', randomNumberInstance.address);
// console.log('randomNumberInstance.address:', randomNumberInstance.address);
Flipper.link(randomnessInstance);
Flipper.link(randomNumberInstance);
// Deploy token contract

flipperInstance = await Flipper.deployed(); //.new(initValue, { from: accounts[0] });
console.log('flipperInstance.address:', flipperInstance.address);
// console.log('flipperInstance.address:', flipperInstance.address);
// delay each test to simulate throttle that isn't available in truffle
setTimeout(function(){ done(); }, 5000);
// setTimeout(function(){ done(); }, 5000);
});
// Check stored value
it("checks stored value", async () => {
Expand All @@ -58,40 +72,67 @@ contract('Flipper', accounts => {

// Set flipped value of existing value
it("should flip the value", async () => {
const previousValue = await flipperInstance.get.call();
await flipperInstance.flip.call({ from: accounts[0] });
const newValue = await flipperInstance.get.call();
assert.notEqual(previousValue, newValue, 'newValue is not opposite of previousValue');
try {
const previousValue = await flipperInstance.get.call();
const value = "1000000000000000000";
await flipperInstance.flip.call({ from: accounts[0], value: value });
setTimeout(function(){ done(); }, 5000);
const newValue = await flipperInstance.get.call();
assert.notEqual(previousValue, newValue, 'newValue is not opposite of previousValue');
} catch (e) {
console.log('error in flip: ', e);
}
});

it("requests randomness", async () => {
const fulfillmentFee = await flipperInstance.MIN_FEE.call();
const refundAddress = await randomNumberInstance.requestRandomness.call(
{ from: accounts[0] },
{ value: fulfillmentFee },
);
const requestId = await randomNumberInstance.requestId.call();
// TEMP ONLY - TRYING TO GET `requestRandomness` TO WORK
try {
const randomnessPrecompileAddress = await randomNumberInstance.randomnessPrecompileAddress.call();
console.log('randomnessPrecompileAddress: ', randomnessPrecompileAddress);
const fulfillmentFee = await randomNumberInstance.MIN_FEE.call();
console.log('fulfillmentFee: ', fulfillmentFee.toString());
console.log('is bn', BN.isBN(fulfillmentFee));
console.log('web3.currentProvider: ', web3.currentProvider);
const refundAddress = await randomNumberInstance.requestRandomness.call(
{ from: accounts[0] },
// same error with large amount
// { value: "1000000000000000000" },
{ value: fulfillmentFee.toString() },
);
console.log('refundAddress: ', refundAddress);
const requestId = await randomNumberInstance.requestId.call();
console.log('requestId: ', requestId);
} catch (e) {
console.log('error in requests randomness: ', e);
}

// Check status of request id from the randomness precompile
// https://github.com/PureStake/moonbeam/blob/master/precompiles/randomness/Randomness.sol#L96
const requestStatus = await randomNumberInstance.getRequestStatus.call(requestId);
// const fulfillmentFee = await randomNumberInstance.MIN_FEE.call();
// const refundAddress = await randomNumberInstance.requestRandomness.call(
// { from: accounts[0] },
// { value: fulfillmentFee },
// );
// const requestId = await randomNumberInstance.requestId.call();
// console.log('requestId: ', requestId);
// // Check status of request id from the randomness precompile
// // https://github.com/PureStake/moonbeam/blob/master/precompiles/randomness/Randomness.sol#L96
// const requestStatus = await randomNumberInstance.getRequestStatus.call(requestId);

// Wait for at least MIN_VRF_BLOCKS_DELAY but less than MAX_VRF_BLOCKS_DELAY
// https://github.com/PureStake/moonbeam/blob/master/precompiles/randomness/Randomness.sol#L13
// https://github.com/PureStake/moonbeam/blob/master/precompiles/randomness/Randomness.sol#L15
const MIN_VRF_BLOCKS_DELAY = await randomNumberInstance.MIN_VRF_BLOCKS_DELAY.call();
for (i=0; i<MIN_VRF_BLOCKS_DELAY.length; i++) {
advanceBlock();
}
const currentBlock = await web3.eth.getBlock("latest");
console.log('currentBlock: ', currentBlock);
assert.equal(currentBlock, 2, 'wrong block');
console.log('requestStatus: ', requestStatus);
assert.equal(requestStatus, 2, 'not ready as expected'); // where 2 in enum is 'READY'
// // Wait for at least MIN_VRF_BLOCKS_DELAY but less than MAX_VRF_BLOCKS_DELAY
// // https://github.com/PureStake/moonbeam/blob/master/precompiles/randomness/Randomness.sol#L13
// // https://github.com/PureStake/moonbeam/blob/master/precompiles/randomness/Randomness.sol#L15
// const MIN_VRF_BLOCKS_DELAY = await randomNumberInstance.MIN_VRF_BLOCKS_DELAY.call();
// for (i=0; i<MIN_VRF_BLOCKS_DELAY.length; i++) {
// advanceBlock();
// }
// const currentBlock = await web3.eth.getBlock("latest");
// console.log('currentBlock: ', currentBlock);
// assert.equal(currentBlock, 2, 'wrong block');
// console.log('requestStatus: ', requestStatus);
// assert.equal(requestStatus, 2, 'not ready as expected'); // where 2 in enum is 'READY'

await randomNumberInstance.fulfillRequest.call();
const random = await randomNumberInstance.random.call();
console.log('random number: ', random[0]);
assert.equal(random[0], '1000', 'not the expected random number');
// await randomNumberInstance.fulfillRequest.call();
// const random = await randomNumberInstance.random.call();
// console.log('random number: ', random[0]);
// assert.equal(random[0], '1000', 'not the expected random number');
});
});
21 changes: 15 additions & 6 deletions dapps/evm2/flipper/truffle-config.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@ const privateKeyDev =
// this is only for demostration purposes only
const privateKeyMoonbase = process.env.MOONBASE_PRIVATE_KEY;

const defaultMoonbaseEndpoint = 'https://rpc.api.moonbase.moonbeam.network';
const defaultMoonbaseNetworkId = 1287;

module.exports = {
networks: {
// Moonbeam Development Network
Expand Down Expand Up @@ -46,22 +49,28 @@ module.exports = {
// https://github.com/trufflesuite/truffle/tree/develop/packages/hdwallet-provider
let args = {
privateKeys: [privateKeyMoonbase],
providerOrUrl: 'https://rpc.api.moonbase.moonbeam.network',
// providerOrUrl: defaultMoonbaseEndpoint,
providerOrUrl: process.env.MOONBASE_BLASTAPI_ENDPOINT,
pollingInterval: 20000, // default only 4000, modifying doesn't help
retryTimeout: 10000, // default 400, modifying doesn't help
};
return new HDWalletProvider(args);
},
// Try to overcome error
// Try to overcome error, changes below might help pass more tests but not as good as
// using BlastApi
// `Uncaught Error: PollingBlockTracker - encountered an error while attempting to update latest block:
// undefined
// https://ethereum.stackexchange.com/questions/97773/truffle-migrate-rinkeby-error-pollingblocktracker-encountered-an-error-whil
confirmations: 10,
timeoutBlocks: 900000,
skipDryRun: false,
skipDryRun: true,
websocket: true,
gas: 5000000,
gasPrice: 40000000000,
gasPrice: 50000000000, // 50 Gwei
networkCheckTimeout: 1000000000,
network_id: 1287,
deploymentPollingInterval: 8000,
network_id: defaultMoonbaseNetworkId,
// network_id: process.env.MOONBASE_BLASTAPI_NETWORK_ID,
},
// faucet for SBY https://docs.astar.network/docs/build/environment/faucet
astar_shibuya: {
Expand All @@ -76,7 +85,7 @@ module.exports = {
},
},
mocha: {
timeout: 100000000, // milliseconds
timeout: 1000000000, // milliseconds
enableTimeouts: false,
bail: false,
retries: 100,
Expand Down