Skip to content

Commit

Permalink
solana: add minter not intialized test for tbtc deposits
Browse files Browse the repository at this point in the history
  • Loading branch information
gator-boi committed Aug 4, 2023
1 parent 5a161ee commit fa10d6d
Showing 1 changed file with 20 additions and 13 deletions.
33 changes: 20 additions & 13 deletions cross-chain/solana/tests/02__wormholeGateway.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,6 @@ async function setup(
const tbtcMint = tbtc.getTokenPDA();
const gatewayWrappedTbtcToken = wormholeGateway.getWrappedTbtcTokenPDA();
const tokenBridgeSender = wormholeGateway.getTokenBridgeSenderPDA();
//const tokenBridgeRedeemer = wormholeGateway.getTokenBridgeRedeemerPDA();

await program.methods
.initialize(new anchor.BN(mintingLimit.toString()))
Expand All @@ -61,6 +60,7 @@ describe("wormhole-gateway", () => {
// Configure the client to use the local cluster.
anchor.setProvider(anchor.AnchorProvider.env());

// Initialize anchor program.
const program = anchor.workspace.WormholeGateway as Program<WormholeGateway>;
const connection = program.provider.connection;

Expand All @@ -85,12 +85,16 @@ describe("wormhole-gateway", () => {

const commonTokenOwner = anchor.web3.Keypair.generate();

// Mock foreign emitter.
const ethereumTokenBridge = new MockEthereumTokenBridge(
ETHEREUM_TOKEN_BRIDGE_ADDRESS
);

it("setup", async () => {
// Max amount of TBTC that can be minted.
const mintingLimit = BigInt(10000);

// Initialize the program.
await setup(program, authority, mintingLimit);
await wormholeGateway.checkState(authority.publicKey, mintingLimit);
await tbtc.checkState(authority, 1, 2, 1500);
Expand Down Expand Up @@ -118,11 +122,7 @@ describe("wormhole-gateway", () => {

it("deposit wrapped tokens", async () => {
const custodian = wormholeGateway.getCustodianPDA();
// TODO: cannot deposit if custodian isn't minter yet.

// Add custodian as minter.
await tbtc.addMinter(authority, custodian);


// Set up new wallet
const payer = await generatePayer(authority);

Expand All @@ -139,15 +139,10 @@ describe("wormhole-gateway", () => {
tbtcMint,
payer.publicKey
);

const [wrappedBefore, tbtcBefore, gatewayBefore] = await Promise.all([
getAccount(connection, recipientWrappedToken),
getAccount(connection, recipientToken),
getAccount(connection, gatewayWrappedTbtcToken),
]);


const depositAmount = BigInt(500);

// Attempt to deposit before the custodian is a minter.
const ix = await wormholeGateway.depositWormholeTbtcIx(
{
recipientWrappedToken,
Expand All @@ -156,6 +151,18 @@ describe("wormhole-gateway", () => {
},
depositAmount
);
await expectIxFail([ix], [payer], "AccountNotInitialized");

// Add custodian as minter.
await tbtc.addMinter(authority, custodian);

// Check token account balances before deposit.
const [wrappedBefore, tbtcBefore, gatewayBefore] = await Promise.all([
getAccount(connection, recipientWrappedToken),
getAccount(connection, recipientToken),
getAccount(connection, gatewayWrappedTbtcToken),
]);

await expectIxSuccess([ix], [payer]);
await tbtc.checkState(authority, 2, 2, 2000);

Expand Down

0 comments on commit fa10d6d

Please sign in to comment.