Get seeds working on RSK

we need to wait for the transactions to be mined otherwise we get a nonce error
This commit is contained in:
bumi 2021-09-28 15:16:26 +02:00
parent 15a08fdaec
commit 8bb3f234c7

View File

@ -1,30 +1,35 @@
const path = require('path'); const path = require("path");
const each = require('async-each-series'); const each = require("async-each-series");
const seeds = require(path.join(__dirname, '..', '/config/seeds.js')); const seeds = require(path.join(__dirname, "..", "/config/seeds.js"));
const { ethers } = require("hardhat"); const { ethers } = require("hardhat");
const Kredits = require('../lib/kredits'); const Kredits = require("../lib/kredits");
async function main() { async function main() {
kredits = new Kredits(hre.ethers.provider, hre.ethers.provider.getSigner()) kredits = new Kredits(hre.ethers.provider, hre.ethers.provider.getSigner());
await kredits.init(); await kredits.init();
let fundingAmount = '2'; const address = await hre.ethers.provider.getSigner().getAddress();
console.log(`Sender account: ${address}`);
let fundingAmount = "2";
each(seeds.funds, (address, next) => { each(seeds.funds, (address, next) => {
console.log(`funding ${address} with 2 ETH`); console.log(`funding ${address} with 2 ETH`);
try { try {
hre.ethers.provider.getSigner().sendTransaction({ hre.ethers.provider.getSigner().sendTransaction({
to: address, to: address,
value: hre.ethers.utils.parseEther(fundingAmount) value: hre.ethers.utils.parseEther(fundingAmount),
}); });
} catch(e) { } catch (e) {
console.log('FAILED:', e); console.log("FAILED:", e);
} }
next(); next();
}); });
each(seeds.contractCalls, (call, next) => { each(
seeds.contractCalls,
(call, next) => {
let [contractName, method, args] = call; let [contractName, method, args] = call;
let contractWrapper = kredits[contractName]; let contractWrapper = kredits[contractName];
let func; let func;
@ -33,16 +38,32 @@ async function main() {
} else { } else {
func = contractWrapper.contract[method]; func = contractWrapper.contract[method];
} }
func.apply(contractWrapper, args).then((result) => { func
console.log(`[OK] kredits.${contractName}.${method}(${JSON.stringify(args)}) => ${result.hash}`); .apply(contractWrapper, args)
.then((result) => {
console.log(
`[OK] kredits.${contractName}.${method}(${JSON.stringify(
args
)}) => ${result.hash}`
);
result.wait().then((r) => {
next(); next();
}).catch((error) => { });
console.log(`[FAILED] kredits.${contractName}.${method}(${JSON.stringify(args)})`); })
.catch((error) => {
console.log(
`[FAILED] kredits.${contractName}.${method}(${JSON.stringify(
args
)})`
);
console.log(`Error: ${error.message}`); console.log(`Error: ${error.message}`);
next(); next();
}); });
}, () => { console.log("\nDone!") }); },
() => {
console.log("\nDone!");
}
);
} }
main(); main();