Skip to content

Commit

Permalink
add integration test
Browse files Browse the repository at this point in the history
  • Loading branch information
solonk8 committed Mar 7, 2024
1 parent 230df91 commit bbe331d
Show file tree
Hide file tree
Showing 7 changed files with 320 additions and 54 deletions.
2 changes: 1 addition & 1 deletion Anchor.toml
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ address = "6Huqrb4xxmmNA4NufYdgpmspoLmjXFd3qEfteCddLgSz" # ocp: policy (allow al
mmm = "mmm3XBJg5gk8XJxEKBvdgptZz6SgK4tXvn36sodowMc"

[scripts]
test = "npx ts-mocha -p ./tsconfig.json -t 1000000 tests/**/*.ts"
test = "npx ts-mocha -p ./tsconfig.json -t 1000000 tests/**/mmm-ext-deposit.spec.ts"

[toolchain]
anchor_version = "0.29.0"
Expand Down
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@
"@metaplex-foundation/umi-bundle-tests": "^0.8.2",
"@metaplex-foundation/umi-web3js-adapters": "^0.8.2",
"@project-serum/anchor": "^0.26.0",
"@solana/spl-token": "^0.3.5",
"@solana/spl-token": "^0.4.1",
"@solana/spl-token-group": "^0.0.1",
"@solana/web3.js": "^1.65.0",
"borsh": "^0.7.0",
"old-mpl-token-metadata": "npm:@metaplex-foundation/[email protected]"
Expand Down
75 changes: 73 additions & 2 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions sdk/src/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,5 +15,6 @@ export enum AllowlistKind {
mint = 2,
mcc = 3,
metadata = 4,
group = 5,
any = 255,
}
50 changes: 2 additions & 48 deletions sdk/src/idl/mmm.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1654,18 +1654,13 @@ export type Mmm = {
"name": "associatedTokenProgram",
"isMut": false,
"isSigner": false
},
{
"name": "rent",
"isMut": false,
"isSigner": false
}
],
"args": [
{
"name": "args",
"type": {
"defined": "ExtDepositeSellArgs"
"defined": "DepositSellArgs"
}
}
]
Expand Down Expand Up @@ -1967,24 +1962,6 @@ export type Mmm = {
]
}
},
{
"name": "ExtDepositeSellArgs",
"type": {
"kind": "struct",
"fields": [
{
"name": "assetAmount",
"type": "u64"
},
{
"name": "allowlistAux",
"type": {
"option": "string"
}
}
]
}
},
{
"name": "SolMip1FulfillSellArgs",
"type": {
Expand Down Expand Up @@ -4001,18 +3978,13 @@ export const IDL: Mmm = {
"name": "associatedTokenProgram",
"isMut": false,
"isSigner": false
},
{
"name": "rent",
"isMut": false,
"isSigner": false
}
],
"args": [
{
"name": "args",
"type": {
"defined": "ExtDepositeSellArgs"
"defined": "DepositSellArgs"
}
}
]
Expand Down Expand Up @@ -4314,24 +4286,6 @@ export const IDL: Mmm = {
]
}
},
{
"name": "ExtDepositeSellArgs",
"type": {
"kind": "struct",
"fields": [
{
"name": "assetAmount",
"type": "u64"
},
{
"name": "allowlistAux",
"type": {
"option": "string"
}
}
]
}
},
{
"name": "SolMip1FulfillSellArgs",
"type": {
Expand Down
112 changes: 112 additions & 0 deletions tests/mmm-ext-deposit.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,112 @@
import * as anchor from '@project-serum/anchor';
import {
getAssociatedTokenAddress,
ASSOCIATED_TOKEN_PROGRAM_ID,
TOKEN_2022_PROGRAM_ID,
} from '@solana/spl-token';
import { Keypair, PublicKey, SystemProgram } from '@solana/web3.js';
import { assert } from 'chai';
import {
Mmm,
AllowlistKind,
getMMMSellStatePDA,
IDL,
MMMProgramID,
} from '../sdk/src';
import {
airdrop,
createPool,
createTestMintAndTokenT22Vanilla,
getEmptyAllowLists,
getTokenAccount2022,
} from './utils';

describe('mmm-ext-deposit', () => {
const { connection } = anchor.AnchorProvider.env();
const wallet = new anchor.Wallet(Keypair.generate());
const provider = new anchor.AnchorProvider(connection, wallet, {
commitment: 'processed',
});
const program = new anchor.Program(
IDL,
MMMProgramID,
provider,
) as anchor.Program<Mmm>;
const cosigner = Keypair.generate();

beforeEach(async () => {
await airdrop(connection, wallet.publicKey, 50);
});

describe('ext_deposit_sell', () => {
it('correctly verifies ANY allowlist when depositing nfts', async () => {
const allowlists = [
{
kind: AllowlistKind.metadata,
allowlist: PublicKey.default,
},
{
kind: AllowlistKind.group,
allowlist: PublicKey.default,
},
...getEmptyAllowLists(1),
];

const { mint, recipientTokenAccount } =
await createTestMintAndTokenT22Vanilla(connection, wallet.payer);
const poolData = await createPool(program, {
owner: wallet.publicKey,
cosigner,
allowlists,
});

const poolAta = await getAssociatedTokenAddress(
mint,
poolData.poolKey,
true,
);

const { key: sellState } = getMMMSellStatePDA(
program.programId,
poolData.poolKey,
mint,
);

assert.equal(await connection.getBalance(poolAta), 0);
assert.equal(await connection.getBalance(sellState), 0);
let poolAccountInfo = await program.account.pool.fetch(poolData.poolKey);
assert.equal(poolAccountInfo.sellsideAssetAmount.toNumber(), 0);

await program.methods
.extDepositSell({
assetAmount: new anchor.BN(1),
allowlistAux: null,
})
.accountsStrict({
owner: wallet.publicKey,
cosigner: cosigner.publicKey,
pool: poolData.poolKey,
assetMint: mint,
assetTokenAccount: recipientTokenAccount,
sellsideEscrowTokenAccount: poolAta,
sellState,
systemProgram: SystemProgram.programId,
tokenProgram: TOKEN_2022_PROGRAM_ID,
associatedTokenProgram: ASSOCIATED_TOKEN_PROGRAM_ID,
})
.signers([cosigner])
.rpc();

let nftEscrow = await getTokenAccount2022(
connection,
poolAta,
TOKEN_2022_PROGRAM_ID,
);
assert.equal(Number(nftEscrow.amount), 1);
assert.equal(nftEscrow.owner.toBase58(), poolData.poolKey.toBase58());
poolAccountInfo = await program.account.pool.fetch(poolData.poolKey);
assert.equal(poolAccountInfo.sellsideAssetAmount.toNumber(), 1);
assert.equal(await connection.getBalance(recipientTokenAccount), 0);
});
});
});
Loading

0 comments on commit bbe331d

Please sign in to comment.