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

Process internal and external plugins together in indexable asset #136

Merged
merged 3 commits into from
May 23, 2024
Merged
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
259 changes: 259 additions & 0 deletions clients/js/test/externalPlugins/oracle.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,11 +45,270 @@ import {
updatePlugin,
fetchAssetV1,
ExternalValidationResult,
ruleSet,
} from '../../src';

const createUmi = async () =>
(await baseCreateUmi()).use(mplCoreOracleExample());

test('it can add oracle to asset for multiple lifecycle events', async (t) => {
const umi = await createUmi();
const account = generateSigner(umi);

// write to example program oracle account
await fixedAccountInit(umi, {
account,
signer: umi.identity,
payer: umi.identity,
args: {
oracleData: {
__kind: 'V1',
create: ExternalValidationResult.Pass,
update: ExternalValidationResult.Rejected,
transfer: ExternalValidationResult.Pass,
burn: ExternalValidationResult.Pass,
},
},
}).sendAndConfirm(umi);

// create asset referencing the oracle account
const asset = await createAsset(umi, {
plugins: [
{
type: 'Oracle',
resultsOffset: {
type: 'Anchor',
},
lifecycleChecks: {
create: [CheckResult.CAN_REJECT],
transfer: [CheckResult.CAN_REJECT],
},
baseAddress: account.publicKey,
},
],
});

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

test('it can add multiple oracles and internal plugins to asset', async (t) => {
const umi = await createUmi();
const account = generateSigner(umi);
const account2 = generateSigner(umi);
const delegateAddress = generateSigner(umi);

// write to example program oracle account
await fixedAccountInit(umi, {
account,
signer: umi.identity,
payer: umi.identity,
args: {
oracleData: {
__kind: 'V1',
create: ExternalValidationResult.Pass,
update: ExternalValidationResult.Rejected,
transfer: ExternalValidationResult.Pass,
burn: ExternalValidationResult.Pass,
},
},
}).sendAndConfirm(umi);

// write to example program oracle account
await fixedAccountInit(umi, {
account: account2,
signer: umi.identity,
payer: umi.identity,
args: {
oracleData: {
__kind: 'V1',
create: ExternalValidationResult.Pass,
update: ExternalValidationResult.Rejected,
transfer: ExternalValidationResult.Pass,
burn: ExternalValidationResult.Pass,
},
},
}).sendAndConfirm(umi);

// create asset referencing the oracle account
const asset = await createAsset(umi, {
plugins: [
{
type: 'TransferDelegate',
},
{
type: 'Oracle',
resultsOffset: {
type: 'Anchor',
},
lifecycleChecks: {
create: [CheckResult.CAN_REJECT],
transfer: [CheckResult.CAN_REJECT],
},
baseAddress: account.publicKey,
},
],
});

await addPlugin(umi, {
asset: asset.publicKey,
plugin: {
type: 'Royalties',
basisPoints: 5,
creators: [{ address: umi.identity.publicKey, percentage: 100 }],
ruleSet: ruleSet('None'),
},
}).sendAndConfirm(umi);

await addPlugin(umi, {
asset: asset.publicKey,
plugin: {
type: 'Oracle',
resultsOffset: {
type: 'Anchor',
},
lifecycleChecks: {
update: [CheckResult.CAN_REJECT],
burn: [CheckResult.CAN_REJECT],
},
baseAddress: account2.publicKey,
},
}).sendAndConfirm(umi);

await addPlugin(umi, {
asset: asset.publicKey,
plugin: {
type: 'FreezeDelegate',
authority: {
type: 'Address',
address: delegateAddress.publicKey,
},
frozen: false,
},
}).sendAndConfirm(umi);

await assertAsset(t, umi, {
...DEFAULT_ASSET,
asset: asset.publicKey,
owner: umi.identity.publicKey,
transferDelegate: {
authority: {
type: 'Owner',
},
},
royalties: {
authority: {
type: 'UpdateAuthority',
},
basisPoints: 5,
creators: [{ address: umi.identity.publicKey, percentage: 100 }],
ruleSet: ruleSet('None'),
},
freezeDelegate: {
authority: {
type: 'Address',
address: delegateAddress.publicKey,
},
frozen: false,
},
oracles: [
{
type: 'Oracle',
resultsOffset: {
type: 'Anchor',
},
authority: {
type: 'UpdateAuthority',
},
baseAddress: account.publicKey,
lifecycleChecks: {
create: [CheckResult.CAN_REJECT],
transfer: [CheckResult.CAN_REJECT],
},
baseAddressConfig: undefined,
},
{
type: 'Oracle',
resultsOffset: {
type: 'Anchor',
},
authority: {
type: 'UpdateAuthority',
},
baseAddress: account2.publicKey,
lifecycleChecks: {
update: [CheckResult.CAN_REJECT],
burn: [CheckResult.CAN_REJECT],
},
baseAddressConfig: undefined,
},
],
});
});

test.skip('add oracle to asset with no offset', async (t) => {
const umi = await createUmi();
const account = generateSigner(umi);

// create asset referencing the oracle account
const asset = await createAsset(umi, {
plugins: [
{
type: 'Oracle',
resultsOffset: {
type: 'NoOffset',
},
lifecycleChecks: {
burn: [CheckResult.CAN_REJECT],
},
baseAddress: account.publicKey,
},
],
});

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

test('it can use fixed address oracle to deny update', async (t) => {
const umi = await createUmi();
const account = generateSigner(umi);
Expand Down
Loading
Loading