Skip to content

Commit

Permalink
README: add accounts;
Browse files Browse the repository at this point in the history
test: add repeated intialization case
brewmaster012 committed Jun 20, 2024

Verified

This commit was signed with the committer’s verified signature.
1 parent bd0102d commit 893ea57
Showing 2 changed files with 35 additions and 6 deletions.
26 changes: 25 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -60,4 +60,28 @@ $ anchor build
To run the tests
```bash
$ anchor test
```
```

# 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.
15 changes: 10 additions & 5 deletions tests/protocol-contracts-solana.ts
Original file line number Diff line number Diff line change
@@ -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 () => {

0 comments on commit 893ea57

Please sign in to comment.