Skip to content

Commit 518f449

Browse files
committed
test: add mint check tests for migration
1 parent 14a2a9d commit 518f449

File tree

2 files changed

+39
-1
lines changed

2 files changed

+39
-1
lines changed

tests/test-utils.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -143,6 +143,7 @@ export async function createMintInstruction(
143143
defaultAccountState = AccountState.Initialized,
144144
vault?: PublicKey,
145145
mintTokens = false,
146+
decimals = 6,
146147
) {
147148
// mint size with extensions
148149
const mintLen = getMintLen([
@@ -164,7 +165,7 @@ export async function createMintInstruction(
164165
createInitializeScaledUiAmountConfigInstruction(mint, extensionAuth, 1.0, TOKEN_2022_PROGRAM_ID),
165166
createInitializeDefaultAccountStateInstruction(mint, AccountState.Initialized, TOKEN_2022_PROGRAM_ID),
166167
createInitializePermanentDelegateInstruction(mint, extensionAuth, TOKEN_2022_PROGRAM_ID),
167-
createInitializeMintInstruction(mint, 6, payer.publicKey, payer.publicKey, TOKEN_2022_PROGRAM_ID),
168+
createInitializeMintInstruction(mint, decimals, payer.publicKey, payer.publicKey, TOKEN_2022_PROGRAM_ID),
168169
];
169170

170171
const tokenAccount = getAssociatedTokenAddressSync(mint, payer.publicKey, false, TOKEN_2022_PROGRAM_ID);

tests/unit/earn.test.ts

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -463,6 +463,9 @@ class EarnTest<V extends Variant = Variant.New> {
463463
this.getEarnGlobalAccount(),
464464
mint.publicKey,
465465
AccountState.Frozen,
466+
undefined,
467+
false,
468+
decimals,
466469
);
467470

468471
let tx = new Transaction();
@@ -1309,6 +1312,40 @@ for (const variant of VARIANTS) {
13091312
.rpc(),
13101313
);
13111314
});
1315+
1316+
test('New m mint has different decimals - reverts', async () => {
1317+
const wrongMint = new Keypair();
1318+
await $.createMMint(wrongMint, $.nonAdmin, 9);
1319+
1320+
await $.expectAnchorError(
1321+
$.earn.methods
1322+
.initialize()
1323+
.accountsPartial({
1324+
admin: $.admin.publicKey,
1325+
mMint: wrongMint.publicKey,
1326+
oldMMint: $.oldMMint!.publicKey,
1327+
})
1328+
.signers([$.admin])
1329+
.rpc(),
1330+
'ConstraintMintDecimals',
1331+
);
1332+
});
1333+
1334+
test('New m mint supply is too large - reverts', async () => {
1335+
await $.mintM($.admin.publicKey, new BN(100_000_000)); // mint 100 m tokens to admin
1336+
1337+
await $.expectSystemError(
1338+
$.earn.methods
1339+
.initialize()
1340+
.accountsPartial({
1341+
admin: $.admin.publicKey,
1342+
mMint: $.mMint.publicKey,
1343+
oldMMint: $.oldMMint!.publicKey,
1344+
})
1345+
.signers([$.admin])
1346+
.rpc(),
1347+
);
1348+
});
13121349
}
13131350

13141351
// given the admin signs the transaction

0 commit comments

Comments
 (0)