git.delta.rocks / unique-network / refs/commits / a85344747647

difftreelog

Merge remote-tracking branch 'origin/feature/NFTPAR-373_chain_extensions' into feature/NFTPAR-366_upstream_updates

Yaroslav Bolyukin2021-06-04parents: #e2828aa #6df0cda.patch.diff
in: master

8 files changed

modified.devcontainer/Dockerfilediffbeforeafterboth
3RUN apt-get update && export DEBIAN_FRONTEND=noninteractive && \3RUN apt-get update && export DEBIAN_FRONTEND=noninteractive && \
4 apt-get -y install --no-install-recommends libssl-dev pkg-config libclang-dev clang4 apt-get -y install --no-install-recommends libssl-dev pkg-config libclang-dev clang
55
6RUN curl -L -o- https://github.com/WebAssembly/binaryen/releases/download/version_101/binaryen-version_101-x86_64-linux.tar.gz | \
7 tar xz --strip-components=1 -C /usr
8
6USER vscode9USER vscode
710
8RUN curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.37.2/install.sh | bash && \11RUN curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.37.2/install.sh | bash && \
14 rustup default nightly-2021-05-30 && \17 rustup default nightly-2021-05-30 && \
15 rustup target add wasm32-unknown-unknown && \18 rustup target add wasm32-unknown-unknown && \
16 rustup component add rustfmt clippy && \19 rustup component add rustfmt clippy && \
17 cargo install cargo-expand cargo-edit20 cargo install cargo-expand cargo-edit cargo-contract
1821
modifiedruntime/src/chain_extension.rsdiffbeforeafterboth
97 let collection = pallet_nft::Module::<C>::get_collection(input.collection_id)?;97 let collection = pallet_nft::Module::<C>::get_collection(input.collection_id)?;
9898
99 pallet_nft::Module::<C>::transfer_internal(99 pallet_nft::Module::<C>::transfer_internal(
100 &C::CrossAccountId::from_sub(env.ext().caller().clone()),100 &C::CrossAccountId::from_sub(env.ext().address().clone()),
101 &C::CrossAccountId::from_sub(input.recipient),101 &C::CrossAccountId::from_sub(input.recipient),
102 &collection,102 &collection,
103 input.token_id,103 input.token_id,
modifiedsmart_contracs/transfer/Cargo.tomldiffbeforeafterboth
4authors = ["[Greg Zaitsev] <[your_email]>"]4authors = ["[Greg Zaitsev] <[your_email]>"]
5edition = "2018"5edition = "2018"
6
7[workspace]
68
7[dependencies]9[dependencies]
8ink_primitives = { git = "https://github.com/usetech-llc/ink", branch = "unique", default-features = false }10ink_primitives = { default-features = false }
9ink_metadata = { git = "https://github.com/usetech-llc/ink", branch = "unique", default-features = false, features = ["derive"], optional = true }11ink_metadata = { default-features = false, features = ["derive"], optional = true }
10ink_env = { git = "https://github.com/usetech-llc/ink", branch = "unique", default-features = false }12ink_env = { default-features = false }
11ink_storage = { git = "https://github.com/usetech-llc/ink", branch = "unique", default-features = false }13ink_storage = { default-features = false }
12ink_lang = { git = "https://github.com/usetech-llc/ink", branch = "unique", default-features = false }14ink_lang = { default-features = false }
1315
14scale = { package = "parity-scale-codec", version = "1.3", default-features = false, features = ["derive"] }16scale = { package = "parity-scale-codec", version = "2.1.1", default-features = false, features = ["derive"] }
15scale-info = { version = "0.4.1", default-features = false, features = ["derive"], optional = true }17scale-info = { version = "0.6.0", default-features = false, features = ["derive"] }
1618
17[lib]19[lib]
18name = "nft_transfer"20name = "nft_transfer"
28 "ink_metadata/std",30 "ink_metadata/std",
29 "ink_env/std",31 "ink_env/std",
30 "ink_storage/std",32 "ink_storage/std",
33 "ink_lang/std",
31 "ink_primitives/std",34 "ink_primitives/std",
32 "scale/std",35 "scale/std",
33 "scale-info/std",36 "scale-info/std",
modifiedsmart_contracs/transfer/lib.rsdiffbeforeafterboth
1#![cfg_attr(not(feature = "std"), no_std)]1#![cfg_attr(not(feature = "std"), no_std)]
2extern crate alloc;
3use alloc::vec::Vec;
24
3use ink_lang as ink;5use ink_lang as ink;
4use ink_env::{Environment, DefaultEnvironment};6use ink_env::{Environment, DefaultEnvironment};
36 }38 }
37}39}
40
41#[derive(scale::Encode, scale::Decode, scale_info::TypeInfo)]
42pub enum CreateItemData {
43 Nft {
44 const_data: Vec<u8>,
45 variable_data: Vec<u8>,
46 },
47 Fungible {
48 value: u128,
49 },
50 ReFungible {
51 const_data: Vec<u8>,
52 variable_data: Vec<u8>,
53 pieces: u128,
54 },
55}
56
57type DefaultAccountId = <DefaultEnvironment as Environment>::AccountId;
3858
39#[ink::chain_extension]59#[ink::chain_extension]
40pub trait NftChainExtension {60pub trait NftChainExtension {
43 /// Transfer one NFT token from sender63 /// Transfer one NFT token from sender
44 ///64 ///
45 #[ink(extension = 0, returns_result = false)]65 #[ink(extension = 0, returns_result = false)]
46 fn transfer(recipient: <DefaultEnvironment as Environment>::AccountId, collection_id: u32, token_id: u32, amount: u128);66 fn transfer(recipient: DefaultAccountId, collection_id: u32, token_id: u32, amount: u128);
67 #[ink(extension = 1, returns_result = false)]
68 fn create_item(owner: DefaultAccountId, collection_id: u32, data: CreateItemData);
69 #[ink(extension = 2, returns_result = false)]
70 fn create_multiple_items(owner: DefaultAccountId, collection_id: u32, data: Vec<CreateItemData>);
71 #[ink(extension = 3, returns_result = false)]
72 fn approve(spender: DefaultAccountId, collection_id: u32, item_id: u32, amount: u128);
73 #[ink(extension = 4, returns_result = false)]
74 fn transfer_from(owner: DefaultAccountId, recipient: DefaultAccountId, collection_id: u32, item_id: u32, amount: u128);
75 #[ink(extension = 5, returns_result = false)]
76 fn set_variable_meta_data(collection_id: u32, item_id: u32, data: Vec<u8>);
77 #[ink(extension = 6, returns_result = false)]
78 fn toggle_white_list(collection_id: u32, address: DefaultAccountId, whitelisted: bool);
47}79}
4880
49#[ink::contract(env = crate::NftEnvironment)]81#[ink::contract(env = crate::NftEnvironment, dynamic_storage_allocator = true)]
50mod nft_transfer {82mod nft_transfer {
83 use alloc::vec::Vec;
84 // use ink_storage::Vec;
85 use crate::CreateItemData;
5186
52 #[ink(storage)]87 #[ink(storage)]
53 pub struct NftTransfer {88 pub struct NftTransfer {
69 .extension()104 .extension()
70 .transfer(recipient, collection_id, token_id, amount);105 .transfer(recipient, collection_id, token_id, amount);
71 }106 }
107 #[ink(message)]
108 pub fn create_item(&mut self, recipient: AccountId, collection_id: u32, data: CreateItemData) {
109 let _ = self.env()
110 .extension()
111 .create_item(recipient, collection_id, data);
112 }
113 #[ink(message)]
114 pub fn create_multiple_items(&mut self, owner: AccountId, collection_id: u32, data: Vec<CreateItemData>) {
115 let _ = self.env()
116 .extension()
117 .create_multiple_items(owner, collection_id, data);
118 }
119 #[ink(message)]
120 pub fn approve(&mut self, spender: AccountId, collection_id: u32, item_id: u32, amount: u128) {
121 let _ = self.env()
122 .extension()
123 .approve(spender, collection_id, item_id, amount);
124 }
125 #[ink(message)]
126 pub fn transfer_from(&mut self, owner: AccountId, recipient: AccountId, collection_id: u32, item_id: u32, amount: u128) {
127 let _ = self.env()
128 .extension()
129 .transfer_from(owner, recipient, collection_id, item_id, amount);
130 }
131 #[ink(message)]
132 pub fn set_variable_meta_data(&mut self, collection_id: u32, item_id: u32, data: Vec<u8>) {
133 let _ = self.env()
134 .extension()
135 .set_variable_meta_data(collection_id, item_id, data);
136 }
137 #[ink(message)]
138 pub fn toggle_white_list(&mut self, collection_id: u32, address: AccountId, whitelisted: bool) {
139 let _ = self.env()
140 .extension()
141 .toggle_white_list(collection_id, address, whitelisted);
142 }
72143
73 }144 }
74145
modifiedtests/src/contracts.test.tsdiffbeforeafterboth
16} from "./util/contracthelpers";16} from "./util/contracthelpers";
1717
18import {18import {
19 addToWhiteListExpectSuccess,
20 approveExpectSuccess,
19 createCollectionExpectSuccess,21 createCollectionExpectSuccess,
20 createItemExpectSuccess,22 createItemExpectSuccess,
23 enablePublicMintingExpectSuccess,
24 enableWhiteListExpectSuccess,
21 getGenericResult,25 getGenericResult,
22 normalizeAccountId26 normalizeAccountId,
27 isWhitelisted,
28 transferFromExpectSuccess
23} from "./util/helpers";29} from "./util/helpers";
2430
2531
26chai.use(chaiAsPromised);32chai.use(chaiAsPromised);
27const expect = chai.expect;33const expect = chai.expect;
2834
29const value = 0;35const value = 0;
30const gasLimit = 3000n * 1000000n;36const gasLimit = 9000n * 1000000n;
31const marketContractAddress = '5CYN9j3YvRkqxewoxeSvRbhAym4465C57uMmX5j4yz99L5H6';37const marketContractAddress = '5CYN9j3YvRkqxewoxeSvRbhAym4465C57uMmX5j4yz99L5H6';
38
39describe('Contracts', () => {
40 it(`Can deploy smart contract Flipper, instantiate it and call it's get and flip messages.`, async () => {
41 await usingApi(async api => {
42 const [contract, deployer] = await deployFlipper(api);
43 const initialGetResponse = await getFlipValue(contract, deployer);
44
45 const bob = privateKey("//Bob");
46 const flip = contract.tx.flip(value, gasLimit);
47 await submitTransactionAsync(bob, flip);
48
49 const afterFlipGetResponse = await getFlipValue(contract, deployer);
50 expect(afterFlipGetResponse).not.to.be.eq(initialGetResponse, 'Flipping should change value.');
51 });
52 });
53
54 it('Can initialize contract instance', async () => {
55 await usingApi(async (api) => {
56 const metadata = JSON.parse(fs.readFileSync('./src/flipper/metadata.json').toString('utf-8'));
57 const abi = new Abi(metadata);
58 const newContractInstance = new Contract(api, abi, marketContractAddress);
59 expect(newContractInstance).to.have.property('address');
60 expect(newContractInstance.address.toString()).to.equal(marketContractAddress);
61 });
62 });
63});
3264
33describe('Contracts', () => {65describe.only('Chain extensions', () => {
34 it(`Can deploy smart contract Flipper, instantiate it and call it's get and flip messages.`, async () => {66 it('Transfer CE', async () => {
35 await usingApi(async api => {67 await usingApi(async api => {
68 const alice = privateKey("//Alice");
69 const bob = privateKey("//Bob");
70
71 // Prep work
72 const collectionId = await createCollectionExpectSuccess();
73 const tokenId = await createItemExpectSuccess(alice, collectionId, 'NFT');
36 const [contract, deployer] = await deployFlipper(api);74 const [contract, deployer] = await deployTransferContract(api);
37 const initialGetResponse = await getFlipValue(contract, deployer);75 const changeAdminTx = api.tx.nft.addCollectionAdmin(collectionId, contract.address);
76 await submitTransactionAsync(alice, changeAdminTx);
3877
39 const bob = privateKey("//Bob");78 const tokenBefore: any = (await api.query.nft.nftItemList(collectionId, tokenId) as any).toJSON();
79
80 // Transfer
40 const flip = contract.tx.flip(value, gasLimit);81 const transferTx = contract.tx.transfer(value, gasLimit, bob.address, collectionId, tokenId, 1);
41 await submitTransactionAsync(bob, flip);82 const events = await submitTransactionAsync(alice, transferTx);
4283 const result = getGenericResult(events);
43 const afterFlipGetResponse = await getFlipValue(contract, deployer);84 const tokenAfter: any = (await api.query.nft.nftItemList(collectionId, tokenId) as any).toJSON();
85
86 // tslint:disable-next-line:no-unused-expression
87 expect(result.success).to.be.true;
44 expect(afterFlipGetResponse).not.to.be.eq(initialGetResponse, 'Flipping should change value.');88 expect(tokenBefore.Owner).to.be.deep.equal(normalizeAccountId(alice.address));
89 expect(tokenAfter.Owner).to.be.deep.equal(normalizeAccountId(bob.address));
45 });90 });
46 });91 });
92
93 it('Mint CE', async () => {
94 await usingApi(async api => {
95 const alice = privateKey('//Alice');
96 const bob = privateKey('//Bob');
97
98 const collectionId = await createCollectionExpectSuccess();
99 const [contract, deployer] = await deployTransferContract(api);
100 await enablePublicMintingExpectSuccess(alice, collectionId);
101 await enableWhiteListExpectSuccess(alice, collectionId);
102 await addToWhiteListExpectSuccess(alice, collectionId, contract.address);
103 await addToWhiteListExpectSuccess(alice, collectionId, bob.address);
104
105 const transferTx = contract.tx.createItem(value, gasLimit, bob.address, collectionId, { Nft: {const_data: '0x010203', variable_data: '0x020304' }});
106 const events = await submitTransactionAsync(alice, transferTx);
107 const result = getGenericResult(events);
108 expect(result.success).to.be.true;
109
110 const tokensAfter: any = (await api.query.nft.nftItemList.entries(collectionId) as any).map((kv: any) => kv[1].toJSON());
111 expect(tokensAfter).to.be.deep.equal([
112 {
113 Owner: bob.address,
114 ConstData: '0x010203',
115 VariableData: '0x020304',
116 },
117 ]);
118 });
119 });
120
121 it('Bulk mint CE', async () => {
122 await usingApi(async api => {
123 const alice = privateKey('//Alice');
124 const bob = privateKey('//Bob');
125
126 const collectionId = await createCollectionExpectSuccess();
127 const [contract, deployer] = await deployTransferContract(api);
128 await enablePublicMintingExpectSuccess(alice, collectionId);
129 await enableWhiteListExpectSuccess(alice, collectionId);
130 await addToWhiteListExpectSuccess(alice, collectionId, contract.address);
131 await addToWhiteListExpectSuccess(alice, collectionId, bob.address);
132
133 const transferTx = contract.tx.createMultipleItems(value, gasLimit, bob.address, collectionId, [
134 { Nft: { const_data: '0x010203', variable_data: '0x020304' } },
135 { Nft: { const_data: '0x010204', variable_data: '0x020305' } },
136 { Nft: { const_data: '0x010205', variable_data: '0x020306' } }
137 ]);
138 const events = await submitTransactionAsync(alice, transferTx);
139 const result = getGenericResult(events);
140 expect(result.success).to.be.true;
141
142 const tokensAfter: any = (await api.query.nft.nftItemList.entries(collectionId) as any)
143 .map((kv: any) => kv[1].toJSON())
144 .sort((a: any, b: any) => a.ConstData.localeCompare(b.ConstData));
145 expect(tokensAfter).to.be.deep.equal([
146 {
147 Owner: bob.address,
148 ConstData: '0x010203',
149 VariableData: '0x020304',
150 },
151 {
152 Owner: bob.address,
153 ConstData: '0x010204',
154 VariableData: '0x020305',
155 },
156 {
157 Owner: bob.address,
158 ConstData: '0x010205',
159 VariableData: '0x020306',
160 },
161 ]);
162 });
163 });
47164
48 it('Can initialize contract instance', async () => {165 it('Approve CE', async () => {
49 await usingApi(async (api) => {166 await usingApi(async api => {
167 const alice = privateKey('//Alice');
168 const bob = privateKey('//Bob');
169 const charlie = privateKey('//Charlie');
170
171 const collectionId = await createCollectionExpectSuccess();
172 const [contract, deployer] = await deployTransferContract(api);
50 const metadata = JSON.parse(fs.readFileSync('./src/flipper/metadata.json').toString('utf-8'));173 const tokenId = await createItemExpectSuccess(alice, collectionId, 'NFT', contract.address.toString());
174
51 const abi = new Abi(metadata);175 const transferTx = contract.tx.approve(value, gasLimit, bob.address, collectionId, tokenId, 1);
52 const newContractInstance = new Contract(api, abi, marketContractAddress);176 const events = await submitTransactionAsync(alice, transferTx);
177 const result = getGenericResult(events);
53 expect(newContractInstance).to.have.property('address');178 expect(result.success).to.be.true;
179
54 expect(newContractInstance.address.toString()).to.equal(marketContractAddress);180 await transferFromExpectSuccess(collectionId, tokenId, bob, contract.address.toString(), charlie, 1, 'NFT');
55 });181 });
56 });182 });
57183
58 it('Can transfer NFT using smart contract.', async () => {184 it('TransferFrom CE', async () => {
59 await usingApi(async api => {185 await usingApi(async api => {
60 const alice = privateKey("//Alice");186 const alice = privateKey('//Alice');
61 const bob = privateKey("//Bob");187 const bob = privateKey('//Bob');
62
63 // Prep work
64 const collectionId = await createCollectionExpectSuccess();188 const charlie = privateKey('//Charlie');
189
65 const tokenId = await createItemExpectSuccess(alice, collectionId, 'NFT');190 const collectionId = await createCollectionExpectSuccess();
66 const [contract, deployer] = await deployTransferContract(api);191 const [contract, deployer] = await deployTransferContract(api);
67 const tokenBefore: any = (await api.query.nft.nftItemList(collectionId, tokenId) as any).toJSON();192 const tokenId = await createItemExpectSuccess(alice, collectionId, 'NFT', bob.address);
68 193 await approveExpectSuccess(collectionId, tokenId, bob, contract.address.toString(), 1);
69 // Transfer194
70 const transferTx = contract.tx.transfer(value, gasLimit, bob.address, collectionId, tokenId, 1);195 const transferTx = contract.tx.transferFrom(value, gasLimit, bob.address, charlie.address, collectionId, tokenId, 1);
71 const events = await submitTransactionAsync(alice, transferTx);196 const events = await submitTransactionAsync(alice, transferTx);
72 const result = getGenericResult(events);197 const result = getGenericResult(events);
198 expect(result.success).to.be.true;
199
73 const tokenAfter: any = (await api.query.nft.nftItemList(collectionId, tokenId) as any).toJSON();200 const token: any = (await api.query.nft.nftItemList(collectionId, tokenId) as any).unwrap()
74
75 // tslint:disable-next-line:no-unused-expression
76 expect(result.success).to.be.true;
77 expect(tokenBefore.Owner).to.be.deep.equal(normalizeAccountId(alice.address));201 expect(token.Owner.toString()).to.be.equal(charlie.address);
78 expect(tokenAfter.Owner).to.be.deep.equal(normalizeAccountId(bob.address));
79 });202 });
80 });203 });
204
205 it('SetVariableMetaData CE', async () => {
206 await usingApi(async api => {
207 const alice = privateKey('//Alice');
208
209 const collectionId = await createCollectionExpectSuccess();
210 const [contract, deployer] = await deployTransferContract(api);
211 const tokenId = await createItemExpectSuccess(alice, collectionId, 'NFT', contract.address.toString());
212
213 const transferTx = contract.tx.setVariableMetaData(value, gasLimit, collectionId, tokenId, '0x121314');
214 const events = await submitTransactionAsync(alice, transferTx);
215 const result = getGenericResult(events);
216 expect(result.success).to.be.true;
217
218 const token: any = (await api.query.nft.nftItemList(collectionId, tokenId) as any).unwrap()
219 expect(token.VariableData.toString()).to.be.equal('0x121314');
220 });
221 });
222
223 it('ToggleWhiteList CE', async () => {
224 await usingApi(async api => {
225 const alice = privateKey('//Alice');
226 const bob = privateKey('//Bob');
227
228 const collectionId = await createCollectionExpectSuccess();
229 const [contract, deployer] = await deployTransferContract(api);
230 const changeAdminTx = api.tx.nft.addCollectionAdmin(collectionId, contract.address);
231 await submitTransactionAsync(alice, changeAdminTx);
232
233 expect(await isWhitelisted(collectionId, bob.address)).to.be.false;
234
235 {
236 const transferTx = contract.tx.toggleWhiteList(value, gasLimit, collectionId, bob.address, true);
237 const events = await submitTransactionAsync(alice, transferTx);
238 const result = getGenericResult(events);
239 expect(result.success).to.be.true;
240
241 expect(await isWhitelisted(collectionId, bob.address)).to.be.true;
242 }
243 {
244 const transferTx = contract.tx.toggleWhiteList(value, gasLimit, collectionId, bob.address, false);
245 const events = await submitTransactionAsync(alice, transferTx);
246 const result = getGenericResult(events);
247 expect(result.success).to.be.true;
248
249 expect(await isWhitelisted(collectionId, bob.address)).to.be.false;
250 }
251 });
252 });
81});253});
82254
modifiedtests/src/transfer_contract/metadata.jsondiffbeforeafterboth
1{1{
2 "metadataVersion": "0.1.0",2 "metadataVersion": "0.1.0",
3 "source": {3 "source": {
4 "hash": "0xfbbc0729acefed9d99f93f6cbb751d12e317958fd0fe183f5781329b37f1bf6e",4 "hash": "0xc6c3f47adeafe86d1674ed72c7179605787842f2f05a2d7da0dbabf3c4fa1aa8",
5 "language": "ink! 3.0.0-rc2",5 "language": "ink! 3.0.0-rc3",
6 "compiler": "rustc 1.51.0-nightly"6 "compiler": "rustc 1.52.0-nightly"
7 },7 },
8 "contract": {8 "contract": {
9 "name": "nft_transfer",9 "name": "nft_transfer",
24 "name": [24 "name": [
25 "default"25 "default"
26 ],26 ],
27 "selector": "0x6a3712e2"27 "selector": "0xed4b9d1b"
28 }28 }
29 ],29 ],
30 "docs": [],30 "docs": [],
78 ],78 ],
79 "payable": false,79 "payable": false,
80 "returnType": null,80 "returnType": null,
81 "selector": "0xfae3a09d"81 "selector": "0x84a15da1"
82 }82 },
83 {
84 "args": [
85 {
86 "name": "recipient",
87 "type": {
88 "displayName": [
89 "AccountId"
90 ],
91 "type": 1
92 }
93 },
94 {
95 "name": "collection_id",
96 "type": {
97 "displayName": [
98 "u32"
99 ],
100 "type": 4
101 }
102 },
103 {
104 "name": "data",
105 "type": {
106 "displayName": [
107 "CreateItemData"
108 ],
109 "type": 6
110 }
111 }
112 ],
113 "docs": [],
114 "mutates": true,
115 "name": [
116 "create_item"
117 ],
118 "payable": false,
119 "returnType": null,
120 "selector": "0xd7c3f083"
121 },
122 {
123 "args": [
124 {
125 "name": "owner",
126 "type": {
127 "displayName": [
128 "AccountId"
129 ],
130 "type": 1
131 }
132 },
133 {
134 "name": "collection_id",
135 "type": {
136 "displayName": [
137 "u32"
138 ],
139 "type": 4
140 }
141 },
142 {
143 "name": "data",
144 "type": {
145 "displayName": [
146 "Vec"
147 ],
148 "type": 8
149 }
150 }
151 ],
152 "docs": [],
153 "mutates": true,
154 "name": [
155 "create_multiple_items"
156 ],
157 "payable": false,
158 "returnType": null,
159 "selector": "0x15f9a1eb"
160 },
161 {
162 "args": [
163 {
164 "name": "spender",
165 "type": {
166 "displayName": [
167 "AccountId"
168 ],
169 "type": 1
170 }
171 },
172 {
173 "name": "collection_id",
174 "type": {
175 "displayName": [
176 "u32"
177 ],
178 "type": 4
179 }
180 },
181 {
182 "name": "item_id",
183 "type": {
184 "displayName": [
185 "u32"
186 ],
187 "type": 4
188 }
189 },
190 {
191 "name": "amount",
192 "type": {
193 "displayName": [
194 "u128"
195 ],
196 "type": 5
197 }
198 }
199 ],
200 "docs": [],
201 "mutates": true,
202 "name": [
203 "approve"
204 ],
205 "payable": false,
206 "returnType": null,
207 "selector": "0x681266a0"
208 },
209 {
210 "args": [
211 {
212 "name": "owner",
213 "type": {
214 "displayName": [
215 "AccountId"
216 ],
217 "type": 1
218 }
219 },
220 {
221 "name": "recipient",
222 "type": {
223 "displayName": [
224 "AccountId"
225 ],
226 "type": 1
227 }
228 },
229 {
230 "name": "collection_id",
231 "type": {
232 "displayName": [
233 "u32"
234 ],
235 "type": 4
236 }
237 },
238 {
239 "name": "item_id",
240 "type": {
241 "displayName": [
242 "u32"
243 ],
244 "type": 4
245 }
246 },
247 {
248 "name": "amount",
249 "type": {
250 "displayName": [
251 "u128"
252 ],
253 "type": 5
254 }
255 }
256 ],
257 "docs": [],
258 "mutates": true,
259 "name": [
260 "transfer_from"
261 ],
262 "payable": false,
263 "returnType": null,
264 "selector": "0x0b396f18"
265 },
266 {
267 "args": [
268 {
269 "name": "collection_id",
270 "type": {
271 "displayName": [
272 "u32"
273 ],
274 "type": 4
275 }
276 },
277 {
278 "name": "item_id",
279 "type": {
280 "displayName": [
281 "u32"
282 ],
283 "type": 4
284 }
285 },
286 {
287 "name": "data",
288 "type": {
289 "displayName": [
290 "Vec"
291 ],
292 "type": 7
293 }
294 }
295 ],
296 "docs": [],
297 "mutates": true,
298 "name": [
299 "set_variable_meta_data"
300 ],
301 "payable": false,
302 "returnType": null,
303 "selector": "0xb0b26da2"
304 },
305 {
306 "args": [
307 {
308 "name": "collection_id",
309 "type": {
310 "displayName": [
311 "u32"
312 ],
313 "type": 4
314 }
315 },
316 {
317 "name": "address",
318 "type": {
319 "displayName": [
320 "AccountId"
321 ],
322 "type": 1
323 }
324 },
325 {
326 "name": "whitelisted",
327 "type": {
328 "displayName": [
329 "bool"
330 ],
331 "type": 9
332 }
333 }
334 ],
335 "docs": [],
336 "mutates": true,
337 "name": [
338 "toggle_white_list"
339 ],
340 "payable": false,
341 "returnType": null,
342 "selector": "0x98574dac"
343 }
83 ]344 ]
84 },345 },
85 "storage": {346 "storage": {
93 "composite": {354 "composite": {
94 "fields": [355 "fields": [
95 {356 {
96 "type": 2357 "type": 2,
358 "typeName": "[u8; 32]"
97 }359 }
98 ]360 ]
99 }361 }
126 "def": {388 "def": {
127 "primitive": "u128"389 "primitive": "u128"
128 }390 }
129 }391 },
392 {
393 "def": {
394 "variant": {
395 "variants": [
396 {
397 "fields": [
398 {
399 "name": "const_data",
400 "type": 7,
401 "typeName": "Vec<u8>"
402 },
403 {
404 "name": "variable_data",
405 "type": 7,
406 "typeName": "Vec<u8>"
407 }
408 ],
409 "name": "Nft"
410 },
411 {
412 "fields": [
413 {
414 "name": "value",
415 "type": 5,
416 "typeName": "u128"
417 }
418 ],
419 "name": "Fungible"
420 },
421 {
422 "fields": [
423 {
424 "name": "const_data",
425 "type": 7,
426 "typeName": "Vec<u8>"
427 },
428 {
429 "name": "variable_data",
430 "type": 7,
431 "typeName": "Vec<u8>"
432 },
433 {
434 "name": "pieces",
435 "type": 5,
436 "typeName": "u128"
437 }
438 ],
439 "name": "ReFungible"
440 }
441 ]
442 }
443 },
444 "path": [
445 "nft_transfer",
446 "CreateItemData"
447 ]
448 },
449 {
450 "def": {
451 "sequence": {
452 "type": 3
453 }
454 }
455 },
456 {
457 "def": {
458 "sequence": {
459 "type": 6
460 }
461 }
462 },
463 {
464 "def": {
465 "primitive": "bool"
466 }
467 }
130 ]468 ]
131}469}
modifiedtests/src/transfer_contract/nft_transfer.wasmdiffbeforeafterboth

binary blob — no preview

modifiedtests/src/util/helpers.tsdiffbeforeafterboth
677 transferFromExpectSuccess(collectionId: number,677 transferFromExpectSuccess(collectionId: number,
678 tokenId: number,678 tokenId: number,
679 accountApproved: IKeyringPair,679 accountApproved: IKeyringPair,
680 accountFrom: IKeyringPair,680 accountFrom: IKeyringPair | CrossAccountId,
681 accountTo: IKeyringPair | CrossAccountId,681 accountTo: IKeyringPair | CrossAccountId,
682 value: number | bigint = 1,682 value: number | bigint = 1,
683 type: string = 'NFT') {683 type: string = 'NFT') {
688 balanceBefore = await api.query.nft.balance(collectionId, toSubstrateAddress(to)) as unknown as BN;688 balanceBefore = await api.query.nft.balance(collectionId, toSubstrateAddress(to)) as unknown as BN;
689 }689 }
690 const transferFromTx = api.tx.nft.transferFrom(690 const transferFromTx = api.tx.nft.transferFrom(
691 normalizeAccountId(accountFrom.address), to, collectionId, tokenId, value);691 normalizeAccountId(accountFrom), to, collectionId, tokenId, value);
692 const events = await submitTransactionAsync(accountApproved, transferFromTx);692 const events = await submitTransactionAsync(accountApproved, transferFromTx);
693 const result = getCreateItemResult(events);693 const result = getCreateItemResult(events);
694 // tslint:disable-next-line:no-unused-expression694 // tslint:disable-next-line:no-unused-expression
950 return whitelisted;950 return whitelisted;
951}951}
952952
953export async function addToWhiteListExpectSuccess(sender: IKeyringPair, collectionId: number, address: string) {953export async function addToWhiteListExpectSuccess(sender: IKeyringPair, collectionId: number, address: string | AccountId) {
954 await usingApi(async (api) => {954 await usingApi(async (api) => {
955955
956 const whiteListedBefore = (await api.query.nft.whiteList(collectionId, address)).toJSON();956 const whiteListedBefore = (await api.query.nft.whiteList(collectionId, address)).toJSON();