Skip to content

Commit

Permalink
Add test for empty account
Browse files Browse the repository at this point in the history
  • Loading branch information
danenbm committed May 9, 2024
1 parent 597d9ee commit 1d2c01f
Showing 1 changed file with 61 additions and 3 deletions.
64 changes: 61 additions & 3 deletions clients/js/test/externalPlugins/oracle.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2390,7 +2390,7 @@ test('it can update oracle to different size external plugin', async (t) => {
});
});

test('create fails but does not panic when oracle account does not exist', async (t) => {
test('it create fails but does not panic when oracle account does not exist', async (t) => {
const umi = await createUmi();
const oracleSigner = generateSigner(umi);

Expand Down Expand Up @@ -2419,7 +2419,7 @@ test('create fails but does not panic when oracle account does not exist', async
await t.throwsAsync(result, { name: 'InvalidOracleAccountData' });
});

test('transfer fails but does not panic when oracle account does not exist', async (t) => {
test('it transfer fails but does not panic when oracle account does not exist', async (t) => {
const umi = await createUmi();
const oracleSigner = generateSigner(umi);

Expand Down Expand Up @@ -2469,7 +2469,7 @@ test('transfer fails but does not panic when oracle account does not exist', asy
await t.throwsAsync(result, { name: 'InvalidOracleAccountData' });
});

test('transfer fails but does not panic when oracle account is too small', async (t) => {
test('it transfer fails but does not panic when oracle account is too small', async (t) => {
const umi = await createUmi();
const newAccount = generateSigner(umi);

Expand Down Expand Up @@ -2526,3 +2526,61 @@ test('transfer fails but does not panic when oracle account is too small', async

await t.throwsAsync(result, { name: 'InvalidOracleAccountData' });
});

test('it empty account does not default to valid oracle', async (t) => {
const umi = await createUmi();
const newAccount = generateSigner(umi);

// Create an invalid oracle account that is an account with 42 bytes.
await createAccount(umi, {
newAccount,
lamports: sol(0.1),
space: 42,
programId: umi.programs.get('mplCore').publicKey,
}).sendAndConfirm(umi);

const asset = await createAsset(umi, {
plugins: [
{
type: 'Oracle',
resultsOffset: {
type: 'NoOffset',
},
lifecycleChecks: {
transfer: [CheckResult.CAN_REJECT],
},
baseAddress: newAccount.publicKey,
},
],
});

await assertAsset(t, umi, {
...DEFAULT_ASSET,
asset: asset.publicKey,
owner: umi.identity.publicKey,
oracles: [
{
type: 'Oracle',
resultsOffset: {
type: 'NoOffset',
},
authority: {
type: 'UpdateAuthority',
},
baseAddress: newAccount.publicKey,
lifecycleChecks: {
transfer: [CheckResult.CAN_REJECT],
},
pda: undefined,
},
],
});

const newOwner = generateSigner(umi);
const result = transfer(umi, {
asset,
newOwner: newOwner.publicKey,
}).sendAndConfirm(umi);

await t.throwsAsync(result, { name: 'UninitializedOracleAccount' });
});

0 comments on commit 1d2c01f

Please sign in to comment.