diff --git a/README.md b/README.md index 29a639c..cc0c714 100644 --- a/README.md +++ b/README.md @@ -60,4 +60,28 @@ $ anchor build To run the tests ```bash $ anchor test -``` \ No newline at end of file +``` + +# Relevant Account and Addresses + +The Gateway program derive a PDA (Program Derived Address) +with seeds `b"meta"` and canonical bump. +This PDA account/address actually holds the SOL +balance of the Gateway program. For SPL tokens, +the PDA derived ATA (Associated Token Account) is +used to hold the SPL token balance. + +The PDA account itself is a data account that holds +Gateway program state, namely the following data types +```rust +pub struct Pda { + nonce: u64, // ensure that each signature can only be used once + tss_address: [u8; 20], // 20 bytes address format of ethereum +} +``` +The `nonce` is incremented on each successful withdraw transaction, +and it's used to prevent replay of signed ECDSA messages. +The `tss_address` is the TSS address of ZetaChain (20Bytes, +Ethereum style). + +The `initialize` instruction sets nonce to 0. \ No newline at end of file diff --git a/tests/protocol-contracts-solana.ts b/tests/protocol-contracts-solana.ts index 2a7351d..8fdf677 100644 --- a/tests/protocol-contracts-solana.ts +++ b/tests/protocol-contracts-solana.ts @@ -23,11 +23,16 @@ describe("some tests", () => { let pda_ata: spl.Account; it("Initializes the program", async () => { - let transaction = new anchor.web3.Transaction(); - console.log("wallet address", wallet.publicKey.toString()); - // Add your test here. - transaction.add(await gatewayProgram.methods.initialize().instruction()); - await anchor.web3.sendAndConfirmTransaction(anchor.getProvider().connection, transaction, [wallet]); + await gatewayProgram.methods.initialize().rpc(); + + // repeated initialization should fail + try { + await gatewayProgram.methods.initialize().rpc(); + throw new Error("Expected error not thrown"); // This line will make the test fail if no error is thrown + } catch (err) { + expect(err).to.be.not.null; + // console.log("Error message: ", err.message) + } }); it("Mint a SPL USDC token", async () => {