|
@@ -4,6 +4,14 @@ const bs58 = require("bs58");
|
|
|
const fs = require("fs");
|
|
const fs = require("fs");
|
|
|
const fetch = require("node-fetch");
|
|
const fetch = require("node-fetch");
|
|
|
import { NodeHttpTransport } from "@improbable-eng/grpc-web-node-http-transport";
|
|
import { NodeHttpTransport } from "@improbable-eng/grpc-web-node-http-transport";
|
|
|
|
|
+const { createHash } = require('crypto');
|
|
|
|
|
+import { TestLib } from "./testlib";
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
|
|
+import {
|
|
|
|
|
+ ChainId,
|
|
|
|
|
+ CHAIN_ID_NEAR,
|
|
|
|
|
+} from "@certusone/wormhole-sdk/lib/cjs/utils";
|
|
|
|
|
|
|
|
function getConfig(env: any) {
|
|
function getConfig(env: any) {
|
|
|
switch (env) {
|
|
switch (env) {
|
|
@@ -22,6 +30,10 @@ function getConfig(env: any) {
|
|
|
return {};
|
|
return {};
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+function hash(string: any) {
|
|
|
|
|
+ return createHash('sha256').update(string).digest('hex');
|
|
|
|
|
+}
|
|
|
|
|
+
|
|
|
async function testDeploy() {
|
|
async function testDeploy() {
|
|
|
let config = getConfig(process.env.NEAR_ENV || "sandbox");
|
|
let config = getConfig(process.env.NEAR_ENV || "sandbox");
|
|
|
|
|
|
|
@@ -56,7 +68,6 @@ async function testDeploy() {
|
|
|
);
|
|
);
|
|
|
|
|
|
|
|
let userKey = nearAPI.utils.KeyPair.fromRandom("ed25519");
|
|
let userKey = nearAPI.utils.KeyPair.fromRandom("ed25519");
|
|
|
- keyStore.setKey(config.networkId, config.userAccount, userKey);
|
|
|
|
|
|
|
|
|
|
console.log(
|
|
console.log(
|
|
|
"creating a user account: " +
|
|
"creating a user account: " +
|
|
@@ -70,43 +81,92 @@ async function testDeploy() {
|
|
|
userKey.getPublicKey(),
|
|
userKey.getPublicKey(),
|
|
|
new BN(10).pow(new BN(27))
|
|
new BN(10).pow(new BN(27))
|
|
|
);
|
|
);
|
|
|
|
|
+
|
|
|
|
|
+ // A whole new world...
|
|
|
|
|
+ keyStore = new nearAPI.keyStores.InMemoryKeyStore();
|
|
|
|
|
+ keyStore.setKey(config.networkId, config.userAccount, userKey);
|
|
|
|
|
+
|
|
|
|
|
+ near = await nearAPI.connect({
|
|
|
|
|
+ deps: {
|
|
|
|
|
+ keyStore,
|
|
|
|
|
+ },
|
|
|
|
|
+ networkId: config.networkId,
|
|
|
|
|
+ nodeUrl: config.nodeUrl,
|
|
|
|
|
+ });
|
|
|
|
|
+
|
|
|
const userAccount = new nearAPI.Account(near.connection, config.userAccount);
|
|
const userAccount = new nearAPI.Account(near.connection, config.userAccount);
|
|
|
|
|
|
|
|
const wormholeContract = await fs.readFileSync(
|
|
const wormholeContract = await fs.readFileSync(
|
|
|
"../contracts/wormhole/target/wasm32-unknown-unknown/release/near_wormhole.wasm"
|
|
"../contracts/wormhole/target/wasm32-unknown-unknown/release/near_wormhole.wasm"
|
|
|
);
|
|
);
|
|
|
|
|
|
|
|
- //console.log("sending money to cover the cost of deploying this contract.. so that we fail for the right reasons");
|
|
|
|
|
- //await userAccount.sendMoney(config.wormholeAccount, new BN("10000000000000000000000000"));
|
|
|
|
|
|
|
+ let h = hash(wormholeContract);
|
|
|
|
|
|
|
|
- keyStore.setKey(config.networkId, config.wormholeAccount, masterKey);
|
|
|
|
|
|
|
+ let ts = new TestLib();
|
|
|
|
|
+ let seq = 1;
|
|
|
|
|
+ let vaa = ts.genCoreUpdate(ts.singleGuardianPrivKey, 0, 0, seq, CHAIN_ID_NEAR, h);
|
|
|
|
|
|
|
|
let wormholeAccount = new nearAPI.Account(
|
|
let wormholeAccount = new nearAPI.Account(
|
|
|
near.connection,
|
|
near.connection,
|
|
|
config.wormholeAccount
|
|
config.wormholeAccount
|
|
|
);
|
|
);
|
|
|
|
|
|
|
|
- try {
|
|
|
|
|
- console.log("redeploying wormhole contract using standard deployment API");
|
|
|
|
|
- let resp = await wormholeAccount.deployContract(wormholeContract);
|
|
|
|
|
- console.log(resp);
|
|
|
|
|
- console.log("This should have thrown a exception..");
|
|
|
|
|
- process.exit(1);
|
|
|
|
|
- } catch {
|
|
|
|
|
- console.log("Exception thrown.. nice.. we dont suck");
|
|
|
|
|
- }
|
|
|
|
|
|
|
+ console.log("submitting vaa");
|
|
|
|
|
+ let result = await userAccount.functionCall({
|
|
|
|
|
+ contractId: config.wormholeAccount,
|
|
|
|
|
+ methodName: "submit_vaa",
|
|
|
|
|
+ args: { vaa: vaa },
|
|
|
|
|
+ attachedDeposit: "12500000000000000000000",
|
|
|
|
|
+ gas: new BN("150000000000000"),
|
|
|
|
|
+ });
|
|
|
|
|
|
|
|
console.log("calling upgradeContract");
|
|
console.log("calling upgradeContract");
|
|
|
- let result = await userAccount.functionCall({
|
|
|
|
|
|
|
+
|
|
|
|
|
+ result = await userAccount.functionCall({
|
|
|
contractId: config.wormholeAccount,
|
|
contractId: config.wormholeAccount,
|
|
|
methodName: "update_contract",
|
|
methodName: "update_contract",
|
|
|
args: wormholeContract,
|
|
args: wormholeContract,
|
|
|
- attachedDeposit: "12500000000000000000000",
|
|
|
|
|
|
|
+ attachedDeposit: "5279790000000000000000000",
|
|
|
gas: 300000000000000,
|
|
gas: 300000000000000,
|
|
|
});
|
|
});
|
|
|
console.log("done");
|
|
console.log("done");
|
|
|
|
|
|
|
|
- console.log(result);
|
|
|
|
|
|
|
+ const tokenContract = await fs.readFileSync(
|
|
|
|
|
+ "../contracts/token-bridge/target/wasm32-unknown-unknown/release/near_token_bridge.wasm"
|
|
|
|
|
+ );
|
|
|
|
|
+
|
|
|
|
|
+ h = hash(tokenContract);
|
|
|
|
|
+ seq = seq + 1
|
|
|
|
|
+ vaa = ts.genTokenUpdate(ts.singleGuardianPrivKey, 0, 0, seq, CHAIN_ID_NEAR, h);
|
|
|
|
|
+
|
|
|
|
|
+ console.log("submitting vaa");
|
|
|
|
|
+ result = await userAccount.functionCall({
|
|
|
|
|
+ contractId: config.tokenAccount,
|
|
|
|
|
+ methodName: "submit_vaa",
|
|
|
|
|
+ args: { vaa: vaa },
|
|
|
|
|
+ attachedDeposit: "12500000000000000000000",
|
|
|
|
|
+ gas: new BN("150000000000000"),
|
|
|
|
|
+ });
|
|
|
|
|
+
|
|
|
|
|
+ console.log("submitting vaa again");
|
|
|
|
|
+ result = await userAccount.functionCall({
|
|
|
|
|
+ contractId: config.tokenAccount,
|
|
|
|
|
+ methodName: "submit_vaa",
|
|
|
|
|
+ args: { vaa: vaa },
|
|
|
|
|
+ attachedDeposit: "12500000000000000000000",
|
|
|
|
|
+ gas: new BN("150000000000000"),
|
|
|
|
|
+ });
|
|
|
|
|
+
|
|
|
|
|
+ console.log("calling upgradeContract on the token bridge");
|
|
|
|
|
+
|
|
|
|
|
+ result = await userAccount.functionCall({
|
|
|
|
|
+ contractId: config.tokenAccount,
|
|
|
|
|
+ methodName: "update_contract",
|
|
|
|
|
+ args: tokenContract,
|
|
|
|
|
+ attachedDeposit: "22797900000000000000000000",
|
|
|
|
|
+ gas: 300000000000000,
|
|
|
|
|
+ });
|
|
|
|
|
+
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
testDeploy();
|
|
testDeploy();
|