Improve seeds script
* Add colors * Inform user about failures at the end of the script
This commit is contained in:
parent
53fafc1c78
commit
75bcde4f49
@ -1,13 +1,16 @@
|
|||||||
const path = require("path");
|
const path = require("path");
|
||||||
|
const colors = require('colors/safe');
|
||||||
const Kredits = require("../lib/kredits");
|
const Kredits = require("../lib/kredits");
|
||||||
const seeds = require(path.join(__dirname, "..", "/config/seeds.js"));
|
const seeds = require(path.join(__dirname, "..", "/config/seeds.js"));
|
||||||
|
|
||||||
|
let somethingFailed = false;
|
||||||
|
|
||||||
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();
|
||||||
|
|
||||||
const address = await hre.ethers.provider.getSigner().getAddress();
|
const address = await hre.ethers.provider.getSigner().getAddress();
|
||||||
console.log(`Sender account: ${address}`);
|
console.log(`Sender account: ${address}\n`);
|
||||||
|
|
||||||
let fundingAmount = "2";
|
let fundingAmount = "2";
|
||||||
|
|
||||||
@ -19,13 +22,14 @@ async function main() {
|
|||||||
to: address,
|
to: address,
|
||||||
value: hre.ethers.utils.parseEther(fundingAmount),
|
value: hre.ethers.utils.parseEther(fundingAmount),
|
||||||
});
|
});
|
||||||
console.log('Done');
|
console.log(colors.green('Done'));
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
console.log("FAILED:", e);
|
somethingFailed = true;
|
||||||
|
console.log(colors.red("FAILED:", e));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
console.log(`Running seeds (${seeds.contractCalls.length} contract calls)...\n`)
|
console.log(`\nRunning seeds (${seeds.contractCalls.length} contract calls)...\n`)
|
||||||
|
|
||||||
for (const call of seeds.contractCalls) {
|
for (const call of seeds.contractCalls) {
|
||||||
const [contractName, method, args] = call;
|
const [contractName, method, args] = call;
|
||||||
@ -40,17 +44,24 @@ async function main() {
|
|||||||
// console.log('result:', result);
|
// console.log('result:', result);
|
||||||
await result.wait();
|
await result.wait();
|
||||||
console.log(
|
console.log(
|
||||||
`[OK] kredits.${contractName}.${method}(${JSON.stringify(
|
`${colors.green('[OK]')} kredits.${contractName}.${method}(${JSON.stringify(
|
||||||
args
|
args
|
||||||
)}) => ${result.hash}`
|
)}) => ${result.hash}`
|
||||||
);
|
);
|
||||||
} catch(error) {
|
} catch(error) {
|
||||||
|
somethingFailed = true;
|
||||||
console.log(
|
console.log(
|
||||||
`[FAILED] kredits.${contractName}.${method}(${JSON.stringify(args)})`
|
`${colors.red('[FAILED]')} kredits.${contractName}.${method}(${JSON.stringify(args)})`
|
||||||
);
|
);
|
||||||
console.log(`Error: ${error.message}`);
|
console.log(`Reason: ${error.message}`);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
main().then(() => console.log("Bravo, all done!"));
|
main().then(() => {
|
||||||
|
if (somethingFailed) {
|
||||||
|
console.log("\nSomething went wrong while running the seeds. Please check the log output above.");
|
||||||
|
} else {
|
||||||
|
console.log("\nBravo, all done!");
|
||||||
|
}
|
||||||
|
});
|
||||||
|
Loading…
x
Reference in New Issue
Block a user