Browse Source

scripts: try catch truffle execs

Change-Id: Id9b27812cd393056ef373d8ec2569ba75f0caea8
Evan Gray 4 years ago
parent
commit
f53d180753
2 changed files with 42 additions and 32 deletions
  1. 28 23
      ethereum/scripts/deploy_test_token.js
  2. 14 9
      ethereum/scripts/register_solana_chain.js

+ 28 - 23
ethereum/scripts/deploy_test_token.js

@@ -3,32 +3,37 @@
 const TokenImplementation = artifacts.require("TokenImplementation")
 
 module.exports = async function(callback) {
-    const accounts = await web3.eth.getAccounts();
+    try {
+        const accounts = await web3.eth.getAccounts();
 
-    // deploy token contract
-    const tokenAddress = (await TokenImplementation.new()).address;
-    const token = new web3.eth.Contract(TokenImplementation.abi, tokenAddress);
+        // deploy token contract
+        const tokenAddress = (await TokenImplementation.new()).address;
+        const token = new web3.eth.Contract(TokenImplementation.abi, tokenAddress);
 
-    console.log("Token deployed at: "+tokenAddress);
+        console.log("Token deployed at: "+tokenAddress);
 
-    // initialize token contract
-    await token.methods.initialize(
-        "Test Token",
-        "TKN",
-        "18",        // decimals
-        accounts[0], // owner
-        "0",
-        "0x00000000000000000000000000000000"
-    ).send({
-        from:accounts[0],
-        gas:1000000
-    });
+        // initialize token contract
+        await token.methods.initialize(
+            "Test Token",
+            "TKN",
+            "18",        // decimals
+            accounts[0], // owner
+            "0",
+            "0x00000000000000000000000000000000"
+        ).send({
+            from:accounts[0],
+            gas:1000000
+        });
 
-    // mint 1000 units
-    await token.methods.mint(accounts[0], "1000000000000000000000").send({
-        from:accounts[0],
-        gas:1000000
-    });
+        // mint 1000 units
+        await token.methods.mint(accounts[0], "1000000000000000000000").send({
+            from:accounts[0],
+            gas:1000000
+        });
 
-    callback();
+        callback();
+    }
+    catch (e) {
+        callback(e);
+    }
 }

+ 14 - 9
ethereum/scripts/register_solana_chain.js

@@ -6,15 +6,20 @@ const TokenImplementation = artifacts.require("TokenImplementation");
 const BridgeImplementationFullABI = jsonfile.readFileSync("../build/contracts/BridgeImplementation.json").abi
 
 module.exports = async function (callback) {
-    const accounts = await web3.eth.getAccounts();
-    const initialized = new web3.eth.Contract(BridgeImplementationFullABI, TokenBridge.address);
+    try {
+        const accounts = await web3.eth.getAccounts();
+        const initialized = new web3.eth.Contract(BridgeImplementationFullABI, TokenBridge.address);
 
-    // Register the Solana endpoint
-    await initialized.methods.registerChain("0x01000000000100c9f4230109e378f7efc0605fb40f0e1869f2d82fda5b1dfad8a5a2dafee85e033d155c18641165a77a2db6a7afbf2745b458616cb59347e89ae0c7aa3e7cc2d400000000010000000100010000000000000000000000000000000000000000000000000000000000000004000000000000000000000000000000000000000000000000000000000000546f6b656e4272696467650100000001c69a1b1a65dd336bf1df6a77afb501fc25db7fc0938cb08595a9ef473265cb4f").send({
-        value: 0,
-        from: accounts[0],
-        gasLimit: 2000000
-    });
+        // Register the Solana endpoint
+        await initialized.methods.registerChain("0x01000000000100c9f4230109e378f7efc0605fb40f0e1869f2d82fda5b1dfad8a5a2dafee85e033d155c18641165a77a2db6a7afbf2745b458616cb59347e89ae0c7aa3e7cc2d400000000010000000100010000000000000000000000000000000000000000000000000000000000000004000000000000000000000000000000000000000000000000000000000000546f6b656e4272696467650100000001c69a1b1a65dd336bf1df6a77afb501fc25db7fc0938cb08595a9ef473265cb4f").send({
+            value: 0,
+            from: accounts[0],
+            gasLimit: 2000000
+        });
 
-    callback();
+        callback();
+    }
+    catch (e) {
+        callback(e);
+    }
 }