Skip to content

Commit 8ea4d6a

Browse files
authored
Add integration tests (metaplex-foundation#1009)
* Add integration tests * Add default rule set creation * Build token metadata dependencies * Fix dependencies build * Change order * Running all tests
1 parent 8283873 commit 8ea4d6a

File tree

4 files changed

+98
-38
lines changed

4 files changed

+98
-38
lines changed

.github/workflows/integration-reusable.yml

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -77,13 +77,12 @@ jobs:
7777
key: program-${{ inputs.name }}-${{ runner.os }}-cargo-${{ hashFiles('**/Cargo.lock') }}
7878
if: ${{ env.CACHE != 'false' }}
7979

80-
# Install JS SDK deps
81-
- uses: ./.github/actions/yarn-install-and-build
80+
# Build Rust Programs
81+
- uses: ./.github/actions/program
8282
with:
83-
cache_id: sdk-${{ inputs.name }}
84-
working_dir: ./${{ inputs.name }}/js
83+
name: token-metadata
84+
if: ${{ inputs.build_token_metadata }}
8585

86-
# Build Rust Programs
8786
- uses: ./.github/actions/build-program
8887
with:
8988
name: token-metadata
@@ -93,6 +92,12 @@ jobs:
9392
with:
9493
name: ${{ inputs.name }}
9594

95+
# Install JS SDK deps
96+
- uses: ./.github/actions/yarn-install-and-build
97+
with:
98+
cache_id: sdk-${{ inputs.name }}
99+
working_dir: ./${{ inputs.name }}/js
100+
96101
# Start local validator
97102
- name: start-local-test-validator
98103
working-directory: ./${{ inputs.name }}/js
@@ -109,4 +114,3 @@ jobs:
109114
working-directory: ./${{ inputs.name }}/js
110115
run: yarn amman:stop
111116
continue-on-error: true
112-

.github/workflows/integration.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ jobs:
2626
node:
2727
- name: "fixed-price-sale"
2828
# - name: "hydra"
29+
- name: "token-metadata"
2930
- name: "candy-machine-core"
3031
uses: ./.github/workflows/integration-reusable.yml
3132
with:

token-metadata/js/test/setup/txs-init.ts

Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,7 @@ import {
7272
TOKEN_PROGRAM_ID,
7373
} from '@solana/spl-token';
7474
import { findTokenRecordPda } from '../utils/programmable';
75+
import { encode } from '@msgpack/msgpack';
7576

7677
export class InitTransactions {
7778
readonly getKeypair: LoadOrGenKeypair | GenLabeledKeypair;
@@ -688,6 +689,86 @@ export class InitTransactions {
688689
};
689690
}
690691

692+
async createDefaultRuleSet(
693+
t: Test,
694+
handler: PayerTransactionHandler,
695+
payer: Keypair,
696+
amount = 1,
697+
): Promise<{
698+
tx: ConfirmedTransactionAssertablePromise;
699+
ruleSet: PublicKey;
700+
}> {
701+
const allowList = [Array.from(PROGRAM_ID.toBytes())];
702+
const transferRules = {
703+
All: {
704+
rules: [
705+
{
706+
Amount: {
707+
amount,
708+
operator: 2 /* equal */,
709+
field: 'Amount',
710+
},
711+
},
712+
{
713+
Any: {
714+
rules: [
715+
{
716+
ProgramOwnedList: {
717+
programs: allowList,
718+
field: 'Destination',
719+
},
720+
},
721+
{
722+
ProgramOwnedList: {
723+
programs: allowList,
724+
field: 'Source',
725+
},
726+
},
727+
{
728+
ProgramOwnedList: {
729+
programs: allowList,
730+
field: 'Authority',
731+
},
732+
},
733+
],
734+
},
735+
},
736+
],
737+
},
738+
};
739+
740+
const ruleSetName = 'default_ruleset_test';
741+
const ruleSet = {
742+
libVersion: 1,
743+
ruleSetName: ruleSetName,
744+
owner: Array.from(payer.publicKey.toBytes()),
745+
operations: {
746+
'Transfer:TransferDelegate': transferRules,
747+
'Delegate:Sale': 'Pass',
748+
'Delegate:Transfer': 'Pass',
749+
'Delegate:LockedTransfer': 'Pass',
750+
},
751+
};
752+
const serializedRuleSet = encode(ruleSet);
753+
754+
// find the rule set PDA
755+
const [ruleSetPda] = PublicKey.findProgramAddressSync(
756+
[Buffer.from('rule_set'), payer.publicKey.toBuffer(), Buffer.from(ruleSetName)],
757+
TOKEN_AUTH_RULES_ID,
758+
);
759+
760+
// creates the rule set
761+
const { tx: createRuleSetTx } = await this.createRuleSet(
762+
t,
763+
payer,
764+
ruleSetPda,
765+
serializedRuleSet,
766+
handler,
767+
);
768+
769+
return { tx: createRuleSetTx, ruleSet: ruleSetPda };
770+
}
771+
691772
async createMintAccount(
692773
payer: Keypair,
693774
connection: Connection,

token-metadata/js/test/transfer.test.ts

Lines changed: 6 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -1082,41 +1082,15 @@ test('Transfer: ProgrammableNonFungible with address lookup table (LUT)', async
10821082
const destination = Keypair.generate();
10831083
amman.airdrop(connection, destination.publicKey, 1);
10841084

1085-
//-- set up our rule set with one pubkey match rule for transfer.
1086-
1087-
const ruleSetName = 'transfer_test';
1088-
const ruleSet = {
1089-
libVersion: 1,
1090-
ruleSetName: ruleSetName,
1091-
owner: Array.from(owner.publicKey.toBytes()),
1092-
operations: {
1093-
'Transfer:Owner': {
1094-
ProgramOwned: {
1095-
program: Array.from(owner.publicKey.toBytes()),
1096-
field: 'Destination',
1097-
},
1098-
},
1099-
},
1100-
};
1101-
const serializedRuleSet = encode(ruleSet);
1102-
1103-
//-- Find the ruleset PDA
1104-
const [ruleSetPda] = PublicKey.findProgramAddressSync(
1105-
[Buffer.from('rule_set'), payer.publicKey.toBuffer(), Buffer.from(ruleSetName)],
1106-
TOKEN_AUTH_RULES_ID,
1107-
);
1108-
1109-
//-- create the ruleset at the PDA address with the serialized ruleset values.
1110-
const { tx: createRuleSetTx } = await API.createRuleSet(
1085+
const { tx: createRuleSetTx, ruleSet: ruleSetPda } = await API.createDefaultRuleSet(
11111086
t,
1112-
payer,
1113-
ruleSetPda,
1114-
serializedRuleSet,
11151087
handler,
1088+
payer,
1089+
1,
11161090
);
11171091
await createRuleSetTx.assertSuccess(t);
11181092

1119-
//-- create an NFT with the programmable config stored on the metadata.
1093+
// create an NFT with the programmable config stored on the metadata.
11201094
const { mint, metadata, masterEdition, token } = await createAndMintDefaultAsset(
11211095
t,
11221096
connection,
@@ -1155,7 +1129,7 @@ test('Transfer: ProgrammableNonFungible with address lookup table (LUT)', async
11551129
const { tx, lookupTable } = await createLookupTable(payer.publicKey, payer, handler, connection);
11561130
await tx.assertSuccess(t);
11571131

1158-
//-- adds addresses to the lookup table
1132+
// adds addresses to the lookup table
11591133

11601134
const addresses = [
11611135
owner.publicKey,
@@ -1206,7 +1180,7 @@ test('Transfer: ProgrammableNonFungible with address lookup table (LUT)', async
12061180

12071181
const lookupTableAccount = await connection.getAddressLookupTable(lookupTable);
12081182

1209-
console.log('[ Waiting for lookup table activation ]');
1183+
console.log('[ waiting for lookup table activation ]');
12101184
await sleep(1000);
12111185

12121186
await createAndSendV0Tx(payer, [transferIx], connection, [lookupTableAccount.value]);

0 commit comments

Comments
 (0)