generated from metaplex-foundation/solana-project-template
-
Notifications
You must be signed in to change notification settings - Fork 28
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #167 from metaplex-foundation/danenbm/merge-in-main
Merge in main - redo without squashing
- Loading branch information
Showing
9 changed files
with
218 additions
and
62 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,130 @@ | ||
import { generateSigner, sol } from '@metaplex-foundation/umi'; | ||
import test from 'ava'; | ||
|
||
import { generateSignerWithSol } from '@metaplex-foundation/umi-bundle-tests'; | ||
import { burnCollection } from '../src'; | ||
import { | ||
DEFAULT_COLLECTION, | ||
assertBurned, | ||
assertCollection, | ||
createAssetWithCollection, | ||
createCollection, | ||
createUmi, | ||
} from './_setupRaw'; | ||
|
||
test('it can burn a collection as the authority', async (t) => { | ||
const umi = await createUmi(); | ||
const collection = await createCollection(umi); | ||
await assertCollection(t, umi, { | ||
...DEFAULT_COLLECTION, | ||
collection: collection.publicKey, | ||
updateAuthority: umi.identity.publicKey, | ||
}); | ||
|
||
await burnCollection(umi, { | ||
collection: collection.publicKey, | ||
compressionProof: null, | ||
}).sendAndConfirm(umi); | ||
|
||
// And the asset address still exists but was resized to 1. | ||
const afterCollection = await assertBurned(t, umi, collection.publicKey); | ||
t.deepEqual(afterCollection.lamports, sol(0.00089784)); | ||
}); | ||
|
||
test('it cannot burn a collection if not the authority', async (t) => { | ||
const umi = await createUmi(); | ||
const attacker = generateSigner(umi); | ||
|
||
const collection = await createCollection(umi); | ||
await assertCollection(t, umi, { | ||
...DEFAULT_COLLECTION, | ||
collection: collection.publicKey, | ||
updateAuthority: umi.identity.publicKey, | ||
}); | ||
|
||
const result = burnCollection(umi, { | ||
collection: collection.publicKey, | ||
authority: attacker, | ||
compressionProof: null, | ||
}).sendAndConfirm(umi); | ||
|
||
await t.throwsAsync(result, { name: 'InvalidAuthority' }); | ||
await assertCollection(t, umi, { | ||
...DEFAULT_COLLECTION, | ||
collection: collection.publicKey, | ||
updateAuthority: umi.identity.publicKey, | ||
}); | ||
}); | ||
|
||
test('it cannot burn a collection if it has Assets in it', async (t) => { | ||
const umi = await createUmi(); | ||
|
||
const { collection } = await createAssetWithCollection(umi, {}); | ||
|
||
await assertCollection(t, umi, { | ||
...DEFAULT_COLLECTION, | ||
collection: collection.publicKey, | ||
updateAuthority: umi.identity.publicKey, | ||
}); | ||
|
||
const result = burnCollection(umi, { | ||
collection: collection.publicKey, | ||
compressionProof: null, | ||
}).sendAndConfirm(umi); | ||
|
||
await t.throwsAsync(result, { name: 'CollectionMustBeEmpty' }); | ||
await assertCollection(t, umi, { | ||
...DEFAULT_COLLECTION, | ||
collection: collection.publicKey, | ||
updateAuthority: umi.identity.publicKey, | ||
}); | ||
}); | ||
|
||
test('it can burn asset with different payer', async (t) => { | ||
const umi = await createUmi(); | ||
const authority = await generateSignerWithSol(umi); | ||
const collection = await createCollection(umi, { | ||
updateAuthority: authority.publicKey, | ||
}); | ||
await assertCollection(t, umi, { | ||
...DEFAULT_COLLECTION, | ||
collection: collection.publicKey, | ||
updateAuthority: authority.publicKey, | ||
}); | ||
|
||
const lamportsBefore = await umi.rpc.getBalance(umi.identity.publicKey); | ||
|
||
await burnCollection(umi, { | ||
collection: collection.publicKey, | ||
payer: umi.identity, | ||
authority, | ||
compressionProof: null, | ||
}).sendAndConfirm(umi); | ||
|
||
// And the asset address still exists but was resized to 1. | ||
const afterCollection = await assertBurned(t, umi, collection.publicKey); | ||
t.deepEqual(afterCollection.lamports, sol(0.00089784)); | ||
|
||
const lamportsAfter = await umi.rpc.getBalance(umi.identity.publicKey); | ||
|
||
t.true(lamportsAfter.basisPoints > lamportsBefore.basisPoints); | ||
}); | ||
|
||
test('it cannot use an invalid noop program for collections', async (t) => { | ||
const umi = await createUmi(); | ||
const collection = await createCollection(umi); | ||
const fakeLogWrapper = generateSigner(umi); | ||
await assertCollection(t, umi, { | ||
...DEFAULT_COLLECTION, | ||
collection: collection.publicKey, | ||
updateAuthority: umi.identity.publicKey, | ||
}); | ||
|
||
const result = burnCollection(umi, { | ||
collection: collection.publicKey, | ||
logWrapper: fakeLogWrapper.publicKey, | ||
compressionProof: null, | ||
}).sendAndConfirm(umi); | ||
|
||
await t.throwsAsync(result, { name: 'InvalidLogWrapperProgram' }); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.