Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[WIP] Solana tests #150

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 0 additions & 11 deletions solana/bridge_token_factory/Anchor.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,3 @@ url = "https://api.apr.dev"
cluster = "Localnet"
wallet = "~/.config/solana/id.json"

[test]
startup_wait = 20000
shutdown_wait = 2000
upgradeable = false

[[test.genesis]]
address = "worm2ZoG2kUd4vFXhvjh93UUH596ayRfgQ2MgjNMTth"
program = "assets/wormhole.so"

[scripts]
test = "yarn run ts-mocha -p ./tsconfig.json -t 1000000 tests/**/*.ts"
4 changes: 4 additions & 0 deletions solana/bridge_token_factory/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
{
"license": "ISC",
"scripts": {
"_test-initialize-simple": "pnpm --filter omni-bridge-solana-tests run test-initialize-simple",
"_test": "pnpm --filter omni-bridge-solana-tests run test",
"test": "anchor test --skip-build",
"pretest": "pnpm --filter omni-bridge-solana-tests run setup-test",
"copy-idl": "copyfiles -u 2 target/types/bridge_token_factory.ts ts/sdk/src && copyfiles -u 2 target/idl/bridge_token_factory.json ts/sdk/src",
"build-devnet": "PROGRAM_ID=\"3ZtEZ8xABFbUr4c1FVpXbQiVdqv4vwhvfCc8HMmhEeua\" anchor build -- --no-default-features --features devnet",
"build-test": "PROGRAM_ID=\"3ZtEZ8xABFbUr4c1FVpXbQiVdqv4vwhvfCc8HMmhEeua\" anchor build -- --no-default-features --features mainnet"
Expand Down
2,116 changes: 2,109 additions & 7 deletions solana/bridge_token_factory/pnpm-lock.yaml

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions solana/bridge_token_factory/pnpm-workspace.yaml
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
packages:
- "ts/sdk"
- "ts/cli"
- "ts/tests"
29 changes: 29 additions & 0 deletions solana/bridge_token_factory/tests/Test.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
[test]
startup_wait = 20000
shutdown_wait = 2000
upgradeable = false

[[test.genesis]]
address = "worm2ZoG2kUd4vFXhvjh93UUH596ayRfgQ2MgjNMTth"
program = "assets/common/wormhole.so"

[[test.validator.account_dir]]
directory = "tests/assets/common"

[[test.validator.account_dir]]
directory = "tests/assets/main"

[[test.validator.account_dir]]
directory = "tests/assets/user/logMetadata/noMetadata"

[[test.validator.account_dir]]
directory = "tests/assets/user/logMetadata/mplMetadata"

[[test.validator.account_dir]]
directory = "tests/assets/user/initTransfer/native"

[[test.validator.account_dir]]
directory = "tests/assets/user/initTransfer/bridged"

[scripts]
test = "pnpm _test"
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
{
"pubkey": "2yVjuQwpsvdsrywzsJJVs9Ueh4zayyo5DYJbBNc3DDpn",
"account": {
"lamports": 1057920,
"data": [
"BAAAAKwAEQ8AAAAAgFEBAGQAAAAAAAAA",
"base64"
],
"owner": "worm2ZoG2kUd4vFXhvjh93UUH596ayRfgQ2MgjNMTth",
"executable": false,
"rentEpoch": 18446744073709551615,
"space": 24
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
{
"pubkey": "9bFNrXNb2WTx8fMHXCheaZqkLZ3YCCaiqTftHxeintHy",
"account": {
"lamports": 252772524,
"data": [
"",
"base64"
],
"owner": "11111111111111111111111111111111",
"executable": false,
"rentEpoch": 18446744073709551615,
"space": 0
}
}
13 changes: 13 additions & 0 deletions solana/bridge_token_factory/tests/assets/main/config.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{
"pubkey": "B6svBaKy3FW1VauuWj8jJ5cfyUq9CM9f2bPntmo66niB",
"account": {
"lamports": 1712160,
"data": [
"mwyq4B76zIKbUkIXpGR+vqTeOuobbFp6NfhUyCEDb0xDmUHDtqNmRAoAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAP3+/////w==",
"base64"
],
"owner": "3ZtEZ8xABFbUr4c1FVpXbQiVdqv4vwhvfCc8HMmhEeua",
"executable": false,
"rentEpoch": 0
}
}
13 changes: 13 additions & 0 deletions solana/bridge_token_factory/tests/assets/main/sequence.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{
"pubkey": "5d3Lf5F3CNFbGFjz41pzfNWzzEA35SxdjN9BZCKik9yc",
"account": {
"lamports": 946560,
"data": [
"AAAAAAAAAAA=",
"base64"
],
"owner": "worm2ZoG2kUd4vFXhvjh93UUH596ayRfgQ2MgjNMTth",
"executable": false,
"rentEpoch": 0
}
}
13 changes: 13 additions & 0 deletions solana/bridge_token_factory/tests/assets/main/solVault.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{
"pubkey": "DcP7sep6ySGF76bwPVFeL3c9o5FBxaWARHPtR8bAiT3W",
"account": {
"lamports": 890880,
"data": [
"",
"base64"
],
"owner": "11111111111111111111111111111111",
"executable": false,
"rentEpoch": 0
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{
"pubkey": "ConfcygdbvZyNQjGjsi2rePyk3JPLXoQ7E5NAWCnF4Zd",
"account": {
"lamports": 1461600,
"data": [
"AQAAAI0hzjjxLJ6JiaJI9CZxRv2dlfYMzfr+/w66dnV3qDk78isxPhIAAAAGAQAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA==",
"base64"
],
"owner": "TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA",
"executable": false,
"rentEpoch": 0
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{
"pubkey": "3ZNCkTisRtqjvwtDqqB9Vk1KKBTW6QEPybQB4aAHbKag",
"account": {
"lamports": 6789883836,
"data": [
"",
"base64"
],
"owner": "11111111111111111111111111111111",
"executable": false,
"rentEpoch": 0
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{
"pubkey": "6i5KGd8Lb3zxYggVV3cSgfNkzQTnBnrpgTANqmiFHJLi",
"account": {
"lamports": 2039280,
"data": [
"r2zocJc2NARMoY6O3PTc1eBx6kKmJY//viNnyiIre3AmAe7+eudS1ue6TFpQNqWtKgC3g3FpA6D6dxiQxQ5W2VWehy4AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAQAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA",
"base64"
],
"owner": "TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA",
"executable": false,
"rentEpoch": 0
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{
"pubkey": "6evD8mRBKMmca4iFF9SS9a8sdoaSzpg2tXt8z5J6HTts",
"account": {
"lamports": 1461600,
"data": [
"AQAAAC8uvK4lfw4BojDMkKKzhd+/gpMW5npRMUitneZcBudPb+zcBQEAAAAGAQAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA==",
"base64"
],
"owner": "TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA",
"executable": false,
"rentEpoch": 0
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{
"pubkey": "EfB7cLDAC7xq29hfEEJARmzYDPBHnijL9JCc1xMkXSur",
"account": {
"lamports": 79083248088,
"data": [
"",
"base64"
],
"owner": "11111111111111111111111111111111",
"executable": false,
"rentEpoch": 0
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{
"pubkey": "Doeb6p1hiUMfg9331QP5U8UvkWQN8w2ZvXRjMcfukB2q",
"account": {
"lamports": 2039280,
"data": [
"VAEWod+7dswcImUUbIUYppMOdhT8xcaaXR/nK/iYGVjK72/Jfl2sGdns0MGRr1qAuIe5Kv8hh7ywn3tUUt20HYRHjQAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAQAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA",
"base64"
],
"owner": "TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA",
"executable": false,
"rentEpoch": 0
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{
"pubkey": "CCUpAhM1emxgJ8i9ESuD4NPpD16z4Hw3wcCXGBhHRv3Q",
"account": {
"lamports": 2039280,
"data": [
"VAEWod+7dswcImUUbIUYppMOdhT8xcaaXR/nK/iYGViNIc448SyeiYmiSPQmcUb9nZX2DM36/v8OunZ1d6g5O4AdAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAQAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA",
"base64"
],
"owner": "TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA",
"executable": false,
"rentEpoch": 0
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{
"pubkey": "6M4QHVoyr5fX6rjULrXb14UMQZNqt6oGSzuYgug78zPm",
"account": {
"lamports": 890880,
"data": [
"BK57i7w86ManQxZEPkCqgGXGQ91VD85QMtZKPYkrHoI6GXjxddrTMEiqOnCKOFvqkc0a0DGyps1200x9wCbYenUEAAAATmFtZQMAAABTbWIDAAAAVXJpAAABAAAAAAAAAQAAAAAAAA==",
"base64"
],
"owner": "metaqbxxUerdq28cj1RbAWkYQm3ybzjb6a8bt518x1s",
"executable": false,
"rentEpoch": 0
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{
"pubkey": "2iSA1BhgQpLPvZeQTJ6quTaGWRYc6AWcVYn2L4CaMxVJ",
"account": {
"lamports": 1461600,
"data": [
"AQAAAK57i7w86ManQxZEPkCqgGXGQ91VD85QMtZKPYkrHoI6SB2qMQAAAAAJAQAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA==",
"base64"
],
"owner": "TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA",
"executable": false,
"rentEpoch": 0
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{
"pubkey": "7K92wLm7Gfy3tgBVmxGyA5ueyYnx5gML1SHsAonby8ay",
"account": {
"lamports": 1461600,
"data": [
"AQAAANqOfce33ccJR8RKQZEAOw7Er2PszfHszRwd6aXEHwQ1Kgf0AQAAAAAGAQAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA==",
"base64"
],
"owner": "TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA",
"executable": false,
"rentEpoch": 0
}
}
14 changes: 14 additions & 0 deletions solana/bridge_token_factory/tests/initialize/simple/Test.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
[test]
startup_wait = 20000
shutdown_wait = 2000
upgradeable = false

[[test.genesis]]
address = "worm2ZoG2kUd4vFXhvjh93UUH596ayRfgQ2MgjNMTth"
program = "../../assets/common/wormhole.so"

[[test.validator.account_dir]]
directory = "tests/assets/common"

[scripts]
test = "pnpm _test-initialize-simple"
16 changes: 6 additions & 10 deletions solana/bridge_token_factory/ts/cli/src/cli.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,10 @@ import {Command} from 'commander';
import {setupContext} from './context';
import {installInitializeCLI} from './initialize';
import {installDeployTokenCLI} from './deployToken';
import {installFinalizeTransferBridgedCLI} from './finalizeTransferBridged';
import {installInitTransferBridgedCLI} from './initTransferBridged';
import {installRegisterMintCLI} from './registerMint';
import {installLogMetadataCLI} from './logMetadata';
import {installCreateTokenCLI} from './createToken';
import {installFinalizeTransferNativeCLI} from './finalizeTransferNative';
import {installInitTransferNativeCLI} from './initTransferNative';
import {installFinalizeTransferCLI} from './finalizeTransfer';
import {installInitTransferCLI} from './initTransfer';

export function cli() {
const program = new Command();
Expand All @@ -29,11 +27,9 @@ export function cli() {
installCreateTokenCLI(program);
installInitializeCLI(program);
installDeployTokenCLI(program);
installFinalizeTransferBridgedCLI(program);
installInitTransferBridgedCLI(program);
installRegisterMintCLI(program);
installFinalizeTransferNativeCLI(program);
installInitTransferNativeCLI(program);
installLogMetadataCLI(program);
installFinalizeTransferCLI(program);
installInitTransferCLI(program);

return program;
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,37 +4,51 @@ import {executeTx} from './executor';
import BN from 'bn.js';
import {parsePubkey} from './keyParser';

export function installFinalizeTransferNativeCLI(program: Command) {
export function installFinalizeTransferCLI(program: Command) {
program
.command('finalize-transfer-native')
.description('Finalize native transfer')
.requiredOption('--mint <pubkey>', 'Mint address')
.requiredOption('--nonce <string>', 'Nonce')
.command('finalize-transfer')
.description('Finalize transfer')
.option('--token <string>', 'Near token address')
.option('--mint <pubkey>', 'Mint address')
.requiredOption('--destination-nonce <string>', 'Nonce')
.requiredOption('--origin-chain <string>', 'Origin chain')
.requiredOption('--origin-nonce <string>', 'Origin nonce')
.requiredOption('--amount <number>', 'Amount')
.option('--recipient <pubkey>', 'Recipient')
.option('--signature <string>', 'Signature')
.action(
async ({
token,
mint,
nonce,
destinationNonce,
originChain,
originNonce,
amount,
recipient,
signature,
}: {
mint: string;
nonce: string;
token?: string;
mint?: string;
destinationNonce: string;
originChain: string;
originNonce: string;
amount: string;
recipient?: string;
signature?: string;
}) => {
const {sdk} = getContext();
const mintPk = await parsePubkey(mint);
const mintPk = mint ? await parsePubkey(mint) : undefined;
const recipientPk = recipient
? await parsePubkey(recipient)
: sdk.provider.publicKey!;
const {instructions, signers} = await sdk.finalizeTransferNative({
const {instructions, signers} = await sdk.finalizeTransfer({
mint: mintPk,
nonce: new BN(nonce),
token,
destinationNonce: new BN(destinationNonce),
transferId: {
originChain: parseInt(originChain),
originNonce: new BN(originNonce),
},
amount: new BN(amount),
recipient: recipientPk,
signature: signature ? JSON.parse(signature) : new Array(65).fill(0),
Expand Down
Loading
Loading