From 3ddbccb8d6f465c5eb0a944952735a290f7b1db0 Mon Sep 17 00:00:00 2001 From: brewmaster012 <88689859+brewmaster012@users.noreply.github.com> Date: Mon, 26 Aug 2024 18:08:01 -0500 Subject: [PATCH 1/2] add ops script --- Anchor.toml | 1 + tests/ops.ts | 90 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 91 insertions(+) create mode 100644 tests/ops.ts diff --git a/Anchor.toml b/Anchor.toml index 351af0a..7c0be5b 100644 --- a/Anchor.toml +++ b/Anchor.toml @@ -16,3 +16,4 @@ wallet = "~/.config/solana/id.json" [scripts] test = "yarn run ts-mocha -p ./tsconfig.json -t 1000000 tests/**/*.ts" +#test = "yarn run ts-mocha -p ./tsconfig.json -t 1000000 tests/ops.ts" diff --git a/tests/ops.ts b/tests/ops.ts new file mode 100644 index 0000000..0ce8199 --- /dev/null +++ b/tests/ops.ts @@ -0,0 +1,90 @@ +// this is for ops on devnet/mainnet +// uncomment Anchor.toml [test] to run this script +// #test = "yarn run ts-mocha -p ./tsconfig.json -t 1000000 tests/ops.ts" + +import * as anchor from "@coral-xyz/anchor"; +import {Program, web3} from "@coral-xyz/anchor"; +import {Gateway} from "../target/types/gateway"; +import {expect} from "chai"; +import {bufferToHex} from "ethereumjs-util"; +import {getAccount} from "@solana/spl-token"; + +const programId = new web3.PublicKey("ZETAjseVjuFsxdRxo6MmTCvqFwb3ZHUx56Co3vCmGis"); + +(async ()=> { + console.log("====================================="); + console.log("BEGIN OPS ON DEVNET........"); + + const provider = anchor.AnchorProvider.local("https://api.devnet.solana.com"); + anchor.setProvider(provider); + console.log("wallet address:", provider.publicKey.toBase58()); + const conn = provider.connection; + const bal = await conn.getBalance(provider.publicKey); + console.log("balance:", bal); + const wallet = anchor.workspace.Gateway.provider.wallet.payer; + console.log("payer address:", wallet.publicKey.toBase58()); + + const acctInfo = await conn.getAccountInfo(programId); + console.log("acctInfo of gateway program :", acctInfo); + + const seeds = [Buffer.from("meta", "utf-8")]; + const [pdaAccount] = anchor.web3.PublicKey.findProgramAddressSync( + seeds, + programId, + ); + console.log("pdaAccount:", pdaAccount.toBase58()); + + const gatewayProgram = anchor.workspace.Gateway as Program; + + console.log("gateway provider", gatewayProgram.provider); + const tssAddress = "0x8531a5ab847ff5b22d855633c25ed1da3255247e"; + // translate the above hex string into an array of number into tssAddress + const tssAddressArray = tssAddress.slice(2).match(/.{1,2}/g).map(byte => parseInt(byte, 16)); + const chain_id = 901; + const chain_id_bn = new anchor.BN(chain_id); + + console.log("tssAddressArray:", tssAddressArray); + console.log("chain_id_bn:", chain_id_bn.toNumber()); + + // Uncomment the following to initialize the gateway program; + // can only be intialized once + // try { + // const inst = await gatewayProgram.methods.initialize(tssAddressArray,chain_id_bn).transaction(); + // console.log("initialize inst:", inst); + // const tx = await anchor.web3.sendAndConfirmTransaction(conn, inst, [wallet]); + // console.log("tx:", tx); + // } catch (err) { + // console.log("intialize err:", err); + // } + + const pdaAccountInfo = await conn.getAccountInfo(pdaAccount); + console.log("pdaAccountInfoData:", pdaAccountInfo.data); + // const pdaAccountData = await gatewayProgram.account.pda.fetch(pdaAccount); + try { + console.log("fetching pda account data....", pdaAccount.toBase58()); + // const data = await gatewayProgram.account.pda.fetch(pdaAccount); + const ainfo = await gatewayProgram.account.pda.fetch(pdaAccount) + console.log(`pda account data: nonce ${ainfo.nonce}`); + const hexAddr = bufferToHex(Buffer.from(ainfo.tssAddress)); + console.log(`pda account data: tss address ${hexAddr}`); + console.log(`authority: ${ainfo.authority.toBase58()}`); + console.log(`depositPaused: ${ainfo.depositPaused}`); + console.log(`chain_id: ${ainfo.chainId}`); + + // console.log(`pda data:`, ainfo); + } catch(e) { + console.log("error:", e); + } + // console.log(`pda account data: nonce ${pdaAccountData.nonce}`); + // const hexAddr = bufferToHex(Buffer.from(pdaAccountData.tssAddress)); + // console.log(`pda account data: tss address ${hexAddr}`); + // console.log(`authority: ${pdaAccountData.authority.toBase58()}`); + + + console.log("END OPS ON DEVNET........") + console.log("====================================="); +})(); + + + + From 3a7e0d5a09447d1d4b900463f9b78252a6bca9cf Mon Sep 17 00:00:00 2001 From: brewmaster012 <88689859+brewmaster012@users.noreply.github.com> Date: Mon, 26 Aug 2024 18:14:00 -0500 Subject: [PATCH 2/2] fix type --- tests/ops.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/ops.ts b/tests/ops.ts index 0ce8199..68c25cf 100644 --- a/tests/ops.ts +++ b/tests/ops.ts @@ -47,14 +47,14 @@ const programId = new web3.PublicKey("ZETAjseVjuFsxdRxo6MmTCvqFwb3ZHUx56Co3vCmGi console.log("chain_id_bn:", chain_id_bn.toNumber()); // Uncomment the following to initialize the gateway program; - // can only be intialized once + // can only be initialized once // try { // const inst = await gatewayProgram.methods.initialize(tssAddressArray,chain_id_bn).transaction(); // console.log("initialize inst:", inst); // const tx = await anchor.web3.sendAndConfirmTransaction(conn, inst, [wallet]); // console.log("tx:", tx); // } catch (err) { - // console.log("intialize err:", err); + // console.log("initialize err:", err); // } const pdaAccountInfo = await conn.getAccountInfo(pdaAccount);