generated from metaplex-foundation/solana-project-template
-
Notifications
You must be signed in to change notification settings - Fork 36
/
Copy pathcreate.test.ts
127 lines (117 loc) · 3.67 KB
/
create.test.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
import { generateSigner, publicKey } from '@metaplex-foundation/umi';
import test from 'ava';
// import { base58 } from '@metaplex-foundation/umi/serializers';
import {
Asset,
AssetWithPlugins,
DataState,
create,
fetchAsset,
fetchAssetWithPlugins,
fetchHashedAsset,
getAssetAccountDataSerializer,
} from '../src';
import { createUmi } from './_setup';
test('it can create a new asset in account state', async (t) => {
// Given a Umi instance and a new signer.
const umi = await createUmi();
const assetAddress = generateSigner(umi);
// When we create a new account.
await create(umi, {
dataState: DataState.AccountState,
assetAddress,
name: 'Test Bread',
uri: 'https://example.com/bread',
plugins: [],
}).sendAndConfirm(umi);
// Then an account was created with the correct data.
const asset = await fetchAsset(umi, assetAddress.publicKey);
// console.log("Account State:", asset);
t.like(asset, <Asset>{
publicKey: assetAddress.publicKey,
updateAuthority: umi.identity.publicKey,
owner: umi.identity.publicKey,
name: 'Test Bread',
uri: 'https://example.com/bread',
});
});
test('it can create a new asset in ledger state', async (t) => {
// Given a Umi instance and a new signer.
const umi = await createUmi();
const assetAddress = generateSigner(umi);
// When we create a new account.
const txResult = await create(umi, {
dataState: DataState.LedgerState,
assetAddress,
name: 'Test Bread',
uri: 'https://example.com/bread',
logWrapper: publicKey('noopb9bkMVfRPU8AsbpTUg8AQkHtKwMYZiFUjNRtMmV'),
plugins: [],
}).sendAndConfirm(umi);
// Then an account was created with the correct data.
const asset = await fetchHashedAsset(umi, assetAddress.publicKey);
// console.log(asset);
t.like(asset, <Asset>{
publicKey: assetAddress.publicKey,
});
const tx = await umi.rpc.getTransaction(txResult.signature);
if (tx && tx.meta.innerInstructions) {
// console.log(tx.meta.innerInstructions[0].instructions);
const { data } = tx.meta.innerInstructions[0].instructions[0];
// console.log(base58.deserialize(data));
const parsed = getAssetAccountDataSerializer().deserialize(data)[0];
// console.log("Ledger State:", parsed);
t.like(parsed, <Asset>{
updateAuthority: umi.identity.publicKey,
owner: umi.identity.publicKey,
name: 'Test Bread',
uri: 'https://example.com/bread',
});
}
});
test('it can create a new asset with plugins', async (t) => {
// Given a Umi instance and a new signer.
const umi = await createUmi();
const assetAddress = generateSigner(umi);
// When we create a new account.
await create(umi, {
dataState: DataState.AccountState,
assetAddress,
name: 'Test Bread',
uri: 'https://example.com/bread',
plugins: [{ __kind: 'Freeze', fields: [{ frozen: false }] }],
}).sendAndConfirm(umi);
// Then an account was created with the correct data.
const asset = await fetchAssetWithPlugins(umi, assetAddress.publicKey);
// console.log("Account State:", asset);
t.like(asset, <AssetWithPlugins>{
publicKey: assetAddress.publicKey,
updateAuthority: umi.identity.publicKey,
owner: umi.identity.publicKey,
name: 'Test Bread',
uri: 'https://example.com/bread',
pluginHeader: {
key: 3,
pluginRegistryOffset: 115,
},
pluginRegistry: {
key: 4,
registry: [
{
pluginType: 2,
offset: 113,
authorities: [{ __kind: 'Owner' }],
},
],
},
plugins: [
{
authorities: [{ __kind: 'Owner' }],
plugin: {
__kind: 'Freeze',
fields: [{ frozen: false }],
},
},
],
});
});