difftreelog
test burn/mint
in: master
2 files changed
tests/src/eth/nonFungible.test.tsdiffbeforeafterboth--- a/tests/src/eth/nonFungible.test.ts
+++ b/tests/src/eth/nonFungible.test.ts
@@ -4,11 +4,13 @@
//
import privateKey from '../substrate/privateKey';
-import { approveExpectSuccess, createCollectionExpectSuccess, createItemExpectSuccess, transferExpectSuccess, transferFromExpectSuccess } from '../util/helpers';
+import { approveExpectSuccess, burnItemExpectSuccess, createCollectionExpectSuccess, createItemExpectSuccess, transferExpectSuccess, transferFromExpectSuccess } from '../util/helpers';
import { collectionIdToAddress, createEthAccount, createEthAccountWithBalance, GAS_ARGS, itWeb3, normalizeEvents, recordEvents, subToEth, transferBalanceToEth } from './util/helpers';
+import { evmToAddress } from '@polkadot/util-crypto';
import nonFungibleAbi from './nonFungibleAbi.json';
import { expect } from 'chai';
import waitNewBlocks from '../substrate/wait-new-blocks';
+import { submitTransactionAsync } from '../substrate/substrate-api';
describe('NFT: Information getting', () => {
itWeb3('totalSupply', async ({ api, web3 }) => {
@@ -64,6 +66,78 @@
});
describe('NFT: Plain calls', () => {
+ itWeb3('Can perform mint()', async ({ web3, api }) => {
+ const collection = await createCollectionExpectSuccess({
+ mode: { type: 'NFT' },
+ });
+ const alice = privateKey('//Alice');
+
+ const caller = await createEthAccountWithBalance(api, web3);
+ const changeAdminTx = api.tx.nft.addCollectionAdmin(collection, { ethereum: caller });
+ await submitTransactionAsync(alice, changeAdminTx);
+ const receiver = createEthAccount(web3);
+
+ const address = collectionIdToAddress(collection);
+ const contract = new web3.eth.Contract(nonFungibleAbi as any, address, {from: caller, ...GAS_ARGS});
+
+ {
+ const nextTokenId = await contract.methods.nextTokenId().call();
+ expect(nextTokenId).to.be.equal('1');
+ const result = await contract.methods.mintWithTokenURI(
+ receiver,
+ nextTokenId,
+ 'Test URI',
+ ).send({from: caller});
+ const events = normalizeEvents(result.events);
+
+ expect(events).to.be.deep.equal([
+ {
+ address,
+ event: 'Transfer',
+ args: {
+ from: '0x0000000000000000000000000000000000000000',
+ to: receiver,
+ tokenId: nextTokenId,
+ },
+ },
+ ]);
+
+ await waitNewBlocks(api, 1);
+ expect(await contract.methods.tokenURI(nextTokenId).call()).to.be.equal('Test URI');
+ }
+ });
+
+ itWeb3('Can perform burn()', async ({ web3, api }) => {
+ const collection = await createCollectionExpectSuccess({
+ mode: {type: 'NFT'},
+ });
+ const alice = privateKey('//Alice');
+
+ const owner = await createEthAccountWithBalance(api, web3);
+
+ const tokenId = await createItemExpectSuccess(alice, collection, 'NFT', { ethereum: owner });
+
+ const address = collectionIdToAddress(collection);
+ const contract = new web3.eth.Contract(nonFungibleAbi as any, address, {from: owner, ...GAS_ARGS});
+
+ {
+ const result = await contract.methods.burn(tokenId).send({ from: owner });
+ const events = normalizeEvents(result.events);
+
+ expect(events).to.be.deep.equal([
+ {
+ address,
+ event: 'Transfer',
+ args: {
+ from: owner,
+ to: '0x0000000000000000000000000000000000000000',
+ tokenId: tokenId.toString(),
+ },
+ },
+ ]);
+ }
+ });
+
itWeb3('Can perform approve()', async ({ web3, api }) => {
const collection = await createCollectionExpectSuccess({
mode: { type: 'NFT' },
@@ -193,6 +267,60 @@
});
describe('NFT: Substrate calls', () => {
+ itWeb3('Events emitted for mint()', async ({ web3 }) => {
+ const collection = await createCollectionExpectSuccess({
+ mode: { type: 'NFT' },
+ });
+ const alice = privateKey('//Alice');
+
+ const address = collectionIdToAddress(collection);
+ const contract = new web3.eth.Contract(nonFungibleAbi as any, address);
+
+ let tokenId: number;
+ const events = await recordEvents(contract, async () => {
+ tokenId = await createItemExpectSuccess(alice, collection, 'NFT');
+ });
+
+ expect(events).to.be.deep.equal([
+ {
+ address,
+ event: 'Transfer',
+ args: {
+ from: '0x0000000000000000000000000000000000000000',
+ to: subToEth(alice.address),
+ tokenId: tokenId!.toString(),
+ },
+ },
+ ]);
+ });
+
+ itWeb3('Events emitted for burn()', async ({ web3 }) => {
+ const collection = await createCollectionExpectSuccess({
+ mode: { type: 'NFT' },
+ });
+ const alice = privateKey('//Alice');
+
+ const address = collectionIdToAddress(collection);
+ const contract = new web3.eth.Contract(nonFungibleAbi as any, address);
+
+ const tokenId = await createItemExpectSuccess(alice, collection, 'NFT');
+ const events = await recordEvents(contract, async () => {
+ await burnItemExpectSuccess(alice, collection, tokenId);
+ });
+
+ expect(events).to.be.deep.equal([
+ {
+ address,
+ event: 'Transfer',
+ args: {
+ from: subToEth(alice.address),
+ to: '0x0000000000000000000000000000000000000000',
+ tokenId: tokenId.toString(),
+ },
+ },
+ ]);
+ });
+
itWeb3('Events emitted for approve()', async ({ web3 }) => {
const collection = await createCollectionExpectSuccess({
mode: { type: 'NFT' },
@@ -284,4 +412,4 @@
},
]);
});
-});
\ No newline at end of file
+});
tests/src/eth/nonFungibleAbi.jsondiffbeforeafterboth1[2 {3 "anonymous": false,4 "inputs": [5 {6 "indexed": true,7 "internalType": "address",8 "name": "owner",9 "type": "address"10 },11 {12 "indexed": true,13 "internalType": "address",14 "name": "approved",15 "type": "address"16 },17 {18 "indexed": true,19 "internalType": "uint256",20 "name": "tokenId",21 "type": "uint256"22 }23 ],24 "name": "Approval",25 "type": "event"26 },27 {28 "anonymous": false,29 "inputs": [30 {31 "indexed": true,32 "internalType": "address",33 "name": "owner",34 "type": "address"35 },36 {37 "indexed": true,38 "internalType": "address",39 "name": "operator",40 "type": "address"41 },42 {43 "indexed": false,44 "internalType": "bool",45 "name": "approved",46 "type": "bool"47 }48 ],49 "name": "ApprovalForAll",50 "type": "event"51 },52 {53 "anonymous": false,54 "inputs": [55 {56 "indexed": true,57 "internalType": "address",58 "name": "from",59 "type": "address"60 },61 {62 "indexed": true,63 "internalType": "address",64 "name": "to",65 "type": "address"66 },67 {68 "indexed": true,69 "internalType": "uint256",70 "name": "tokenId",71 "type": "uint256"72 }73 ],74 "name": "Transfer",75 "type": "event"76 },77 {78 "inputs": [79 {80 "internalType": "address",81 "name": "approved",82 "type": "address"83 },84 {85 "internalType": "uint256",86 "name": "tokenId",87 "type": "uint256"88 }89 ],90 "name": "approve",91 "outputs": [],92 "stateMutability": "payable",93 "type": "function"94 },95 {96 "inputs": [97 {98 "internalType": "address",99 "name": "owner",100 "type": "address"101 }102 ],103 "name": "balanceOf",104 "outputs": [105 {106 "internalType": "uint256",107 "name": "",108 "type": "uint256"109 }110 ],111 "stateMutability": "view",112 "type": "function"113 },114 {115 "inputs": [116 {117 "internalType": "uint256",118 "name": "tokenId",119 "type": "uint256"120 }121 ],122 "name": "getApproved",123 "outputs": [124 {125 "internalType": "address",126 "name": "",127 "type": "address"128 }129 ],130 "stateMutability": "view",131 "type": "function"132 },133 {134 "inputs": [135 {136 "internalType": "address",137 "name": "owner",138 "type": "address"139 },140 {141 "internalType": "address",142 "name": "operator",143 "type": "address"144 }145 ],146 "name": "isApprovedForAll",147 "outputs": [148 {149 "internalType": "bool",150 "name": "",151 "type": "bool"152 }153 ],154 "stateMutability": "view",155 "type": "function"156 },157 {158 "inputs": [],159 "name": "name",160 "outputs": [161 {162 "internalType": "string",163 "name": "res_name",164 "type": "string"165 }166 ],167 "stateMutability": "view",168 "type": "function"169 },170 {171 "inputs": [172 {173 "internalType": "uint256",174 "name": "tokenId",175 "type": "uint256"176 }177 ],178 "name": "ownerOf",179 "outputs": [180 {181 "internalType": "address",182 "name": "",183 "type": "address"184 }185 ],186 "stateMutability": "view",187 "type": "function"188 },189 {190 "inputs": [191 {192 "internalType": "address",193 "name": "from",194 "type": "address"195 },196 {197 "internalType": "address",198 "name": "to",199 "type": "address"200 },201 {202 "internalType": "uint256",203 "name": "tokenId",204 "type": "uint256"205 }206 ],207 "name": "safeTransferFrom",208 "outputs": [],209 "stateMutability": "payable",210 "type": "function"211 },212 {213 "inputs": [214 {215 "internalType": "address",216 "name": "from",217 "type": "address"218 },219 {220 "internalType": "address",221 "name": "to",222 "type": "address"223 },224 {225 "internalType": "uint256",226 "name": "tokenId",227 "type": "uint256"228 },229 {230 "internalType": "bytes",231 "name": "data",232 "type": "bytes"233 }234 ],235 "name": "safeTransferFrom",236 "outputs": [],237 "stateMutability": "payable",238 "type": "function"239 },240 {241 "inputs": [242 {243 "internalType": "address",244 "name": "operator",245 "type": "address"246 },247 {248 "internalType": "bool",249 "name": "approved",250 "type": "bool"251 }252 ],253 "name": "setApprovalForAll",254 "outputs": [],255 "stateMutability": "nonpayable",256 "type": "function"257 },258 {259 "inputs": [260 {261 "internalType": "bytes4",262 "name": "interfaceID",263 "type": "bytes4"264 }265 ],266 "name": "supportsInterface",267 "outputs": [268 {269 "internalType": "bool",270 "name": "",271 "type": "bool"272 }273 ],274 "stateMutability": "pure",275 "type": "function"276 },277 {278 "inputs": [],279 "name": "symbol",280 "outputs": [281 {282 "internalType": "string",283 "name": "res_symbol",284 "type": "string"285 }286 ],287 "stateMutability": "view",288 "type": "function"289 },290 {291 "inputs": [292 {293 "internalType": "uint256",294 "name": "index",295 "type": "uint256"296 }297 ],298 "name": "tokenByIndex",299 "outputs": [300 {301 "internalType": "uint256",302 "name": "",303 "type": "uint256"304 }305 ],306 "stateMutability": "view",307 "type": "function"308 },309 {310 "inputs": [311 {312 "internalType": "address",313 "name": "owner",314 "type": "address"315 },316 {317 "internalType": "uint256",318 "name": "index",319 "type": "uint256"320 }321 ],322 "name": "tokenOfOwnerByIndex",323 "outputs": [324 {325 "internalType": "uint256",326 "name": "",327 "type": "uint256"328 }329 ],330 "stateMutability": "view",331 "type": "function"332 },333 {334 "inputs": [335 {336 "internalType": "uint256",337 "name": "tokenId",338 "type": "uint256"339 }340 ],341 "name": "tokenURI",342 "outputs": [343 {344 "internalType": "string",345 "name": "",346 "type": "string"347 }348 ],349 "stateMutability": "view",350 "type": "function"351 },352 {353 "inputs": [],354 "name": "totalSupply",355 "outputs": [356 {357 "internalType": "uint256",358 "name": "",359 "type": "uint256"360 }361 ],362 "stateMutability": "view",363 "type": "function"364 },365 {366 "inputs": [367 {368 "internalType": "address",369 "name": "from",370 "type": "address"371 },372 {373 "internalType": "address",374 "name": "to",375 "type": "address"376 },377 {378 "internalType": "uint256",379 "name": "tokenId",380 "type": "uint256"381 }382 ],383 "name": "transferFrom",384 "outputs": [],385 "stateMutability": "payable",386 "type": "function"387 },388 {389 "inputs": [390 {391 "internalType": "address",392 "name": "to",393 "type": "address"394 },395 {396 "internalType": "uint256",397 "name": "tokenId",398 "type": "uint256"399 }400 ],401 "name": "transfer",402 "outputs": [],403 "stateMutability": "payable",404 "type": "function"405 }406]