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

difftreelog

fix rft test

Trubnikov Sergey2022-12-15parent: #a37fff1.patch.diff
in: master

6 files changed

modifiedpallets/refungible/src/stubs/UniqueRefungible.rawdiffbeforeafterboth

binary blob — no preview

modifiedpallets/refungible/src/stubs/UniqueRefungible.soldiffbeforeafterboth
18}18}
1919
20/// @title A contract that allows to set and delete token properties and change token property permissions.20/// @title A contract that allows to set and delete token properties and change token property permissions.
21/// @dev the ERC-165 identifier for this interface is 0x91a97a6821/// @dev the ERC-165 identifier for this interface is 0xde0695c2
22contract TokenProperties is Dummy, ERC165 {22contract TokenProperties is Dummy, ERC165 {
23 // /// @notice Set permissions for token property.
24 // /// @dev Throws error if `msg.sender` is not admin or owner of the collection.
25 // /// @param key Property key.
26 // /// @param isMutable Permission to mutate property.
27 // /// @param collectionAdmin Permission to mutate property by collection admin if property is mutable.
28 // /// @param tokenOwner Permission to mutate property by token owner if property is mutable.
29 // /// @dev EVM selector for this function is: 0x222d97fa,
30 // /// or in textual repr: setTokenPropertyPermission(string,bool,bool,bool)
31 // function setTokenPropertyPermission(string memory key, bool isMutable, bool collectionAdmin, bool tokenOwner) public {
32 // require(false, stub_error);
33 // key;
34 // isMutable;
35 // collectionAdmin;
36 // tokenOwner;
37 // dummy = 0;
38 // }
39
23 /// @notice Set permissions for token property.40 /// @notice Set permissions for token property.
24 /// @dev Throws error if `msg.sender` is not admin or owner of the collection.41 /// @dev Throws error if `msg.sender` is not admin or owner of the collection.
25 /// @param key Property key.42 /// @param permissions Permissions for keys.
26 /// @param isMutable Permission to mutate property.
27 /// @param collectionAdmin Permission to mutate property by collection admin if property is mutable.
28 /// @param tokenOwner Permission to mutate property by token owner if property is mutable.
29 /// @dev EVM selector for this function is: 0x222d97fa,43 /// @dev EVM selector for this function is: 0xbd92983a,
30 /// or in textual repr: setTokenPropertyPermission(string,bool,bool,bool)44 /// or in textual repr: setTokenPropertyPermissions((string,(uint8,bool)[])[])
31 function setTokenPropertyPermission(45 function setTokenPropertyPermissions(Tuple53[] memory permissions) public {
32 string memory key,
33 bool isMutable,
34 bool collectionAdmin,
35 bool tokenOwner
36 ) public {
37 require(false, stub_error);46 require(false, stub_error);
38 key;47 permissions;
39 isMutable;
40 collectionAdmin;
41 tokenOwner;
42 dummy = 0;48 dummy = 0;
43 }49 }
50
51 /// @notice Get permissions for token properties.
52 /// @dev EVM selector for this function is: 0xf23d7790,
53 /// or in textual repr: tokenPropertyPermissions()
54 function tokenPropertyPermissions() public view returns (Tuple53[] memory) {
55 require(false, stub_error);
56 dummy;
57 return new Tuple53[](0);
58 }
4459
45 // /// @notice Set token property value.60 // /// @notice Set token property value.
46 // /// @dev Throws error if `msg.sender` has no permission to edit the property.61 // /// @dev Throws error if `msg.sender` has no permission to edit the property.
118 bytes value;133 bytes value;
119}134}
135
136enum EthTokenPermissions {
137 Mutable,
138 TokenOwner,
139 CollectionAdmin
140}
141
142/// @dev anonymous struct
143struct Tuple53 {
144 string field_0;
145 Tuple51[] field_1;
146}
147
148/// @dev anonymous struct
149struct Tuple51 {
150 EthTokenPermissions field_0;
151 bool field_1;
152}
120153
121/// @title A contract that allows you to work with collections.154/// @title A contract that allows you to work with collections.
122/// @dev the ERC-165 identifier for this interface is 0xb5e1747f155/// @dev the ERC-165 identifier for this interface is 0xb5e1747f
modifiedtests/src/eth/abi/reFungible.jsondiffbeforeafterboth
679 },679 },
680 {680 {
681 "inputs": [681 "inputs": [
682 {
683 "components": [
682 { "internalType": "string", "name": "key", "type": "string" },684 { "internalType": "string", "name": "field_0", "type": "string" },
685 {
686 "components": [
683 { "internalType": "bool", "name": "isMutable", "type": "bool" },687 {
688 "internalType": "enum EthTokenPermissions",
689 "name": "field_0",
690 "type": "uint8"
691 },
684 { "internalType": "bool", "name": "collectionAdmin", "type": "bool" },692 { "internalType": "bool", "name": "field_1", "type": "bool" }
693 ],
694 "internalType": "struct Tuple51[]",
695 "name": "field_1",
696 "type": "tuple[]"
697 }
698 ],
685 { "internalType": "bool", "name": "tokenOwner", "type": "bool" }699 "internalType": "struct Tuple53[]",
700 "name": "permissions",
701 "type": "tuple[]"
702 }
686 ],703 ],
687 "name": "setTokenPropertyPermission",704 "name": "setTokenPropertyPermissions",
688 "outputs": [],705 "outputs": [],
689 "stateMutability": "nonpayable",706 "stateMutability": "nonpayable",
690 "type": "function"707 "type": "function"
733 "stateMutability": "view",750 "stateMutability": "view",
734 "type": "function"751 "type": "function"
735 },752 },
753 {
754 "inputs": [],
755 "name": "tokenPropertyPermissions",
756 "outputs": [
757 {
758 "components": [
759 { "internalType": "string", "name": "field_0", "type": "string" },
760 {
761 "components": [
762 {
763 "internalType": "enum EthTokenPermissions",
764 "name": "field_0",
765 "type": "uint8"
766 },
767 { "internalType": "bool", "name": "field_1", "type": "bool" }
768 ],
769 "internalType": "struct Tuple51[]",
770 "name": "field_1",
771 "type": "tuple[]"
772 }
773 ],
774 "internalType": "struct Tuple53[]",
775 "name": "",
776 "type": "tuple[]"
777 }
778 ],
779 "stateMutability": "view",
780 "type": "function"
781 },
736 {782 {
737 "inputs": [783 "inputs": [
738 { "internalType": "uint256", "name": "tokenId", "type": "uint256" }784 { "internalType": "uint256", "name": "tokenId", "type": "uint256" }
modifiedtests/src/eth/api/UniqueRefungible.soldiffbeforeafterboth
13}13}
1414
15/// @title A contract that allows to set and delete token properties and change token property permissions.15/// @title A contract that allows to set and delete token properties and change token property permissions.
16/// @dev the ERC-165 identifier for this interface is 0x91a97a6816/// @dev the ERC-165 identifier for this interface is 0xde0695c2
17interface TokenProperties is Dummy, ERC165 {17interface TokenProperties is Dummy, ERC165 {
18 // /// @notice Set permissions for token property.
19 // /// @dev Throws error if `msg.sender` is not admin or owner of the collection.
20 // /// @param key Property key.
21 // /// @param isMutable Permission to mutate property.
22 // /// @param collectionAdmin Permission to mutate property by collection admin if property is mutable.
23 // /// @param tokenOwner Permission to mutate property by token owner if property is mutable.
24 // /// @dev EVM selector for this function is: 0x222d97fa,
25 // /// or in textual repr: setTokenPropertyPermission(string,bool,bool,bool)
26 // function setTokenPropertyPermission(string memory key, bool isMutable, bool collectionAdmin, bool tokenOwner) external;
27
18 /// @notice Set permissions for token property.28 /// @notice Set permissions for token property.
19 /// @dev Throws error if `msg.sender` is not admin or owner of the collection.29 /// @dev Throws error if `msg.sender` is not admin or owner of the collection.
20 /// @param key Property key.30 /// @param permissions Permissions for keys.
21 /// @param isMutable Permission to mutate property.
22 /// @param collectionAdmin Permission to mutate property by collection admin if property is mutable.
23 /// @param tokenOwner Permission to mutate property by token owner if property is mutable.
24 /// @dev EVM selector for this function is: 0x222d97fa,31 /// @dev EVM selector for this function is: 0xbd92983a,
25 /// or in textual repr: setTokenPropertyPermission(string,bool,bool,bool)32 /// or in textual repr: setTokenPropertyPermissions((string,(uint8,bool)[])[])
26 function setTokenPropertyPermission(33 function setTokenPropertyPermissions(Tuple47[] memory permissions) external;
27 string memory key,34
28 bool isMutable,35 /// @notice Get permissions for token properties.
29 bool collectionAdmin,36 /// @dev EVM selector for this function is: 0xf23d7790,
30 bool tokenOwner37 /// or in textual repr: tokenPropertyPermissions()
31 ) external;38 function tokenPropertyPermissions() external view returns (Tuple47[] memory);
3239
33 // /// @notice Set token property value.40 // /// @notice Set token property value.
34 // /// @dev Throws error if `msg.sender` has no permission to edit the property.41 // /// @dev Throws error if `msg.sender` has no permission to edit the property.
79 bytes value;86 bytes value;
80}87}
88
89enum EthTokenPermissions {
90 Mutable,
91 TokenOwner,
92 CollectionAdmin
93}
94
95/// @dev anonymous struct
96struct Tuple47 {
97 string field_0;
98 Tuple45[] field_1;
99}
100
101/// @dev anonymous struct
102struct Tuple45 {
103 EthTokenPermissions field_0;
104 bool field_1;
105}
81106
82/// @title A contract that allows you to work with collections.107/// @title A contract that allows you to work with collections.
83/// @dev the ERC-165 identifier for this interface is 0xb5e1747f108/// @dev the ERC-165 identifier for this interface is 0xb5e1747f
modifiedtests/src/eth/events.test.tsdiffbeforeafterboth
119 ethEvents.push(event);119 ethEvents.push(event);
120 });120 });
121 const {unsubscribe, collectedEvents: subEvents} = await helper.subscribeEvents([{section: 'common', names: ['PropertyPermissionSet']}]);121 const {unsubscribe, collectedEvents: subEvents} = await helper.subscribeEvents([{section: 'common', names: ['PropertyPermissionSet']}]);
122 await collection.methods.setTokenPropertyPermission('testKey', true, true, true).send({from: owner});122 await collection.methods.setTokenPropertyPermissions([['testKey', [[0, true], [1, true], [2, true]]]]).send({from: owner});
123 await helper.wait.newBlocks(1);123 await helper.wait.newBlocks(1);
124 expect(ethEvents).to.be.like([124 expect(ethEvents).to.be.like([
125 {125 {
374 const collectionHelper = helper.ethNativeContract.collectionHelpers(owner);374 const collectionHelper = helper.ethNativeContract.collectionHelpers(owner);
375 const result = await collection.methods.mint(owner).send({from: owner});375 const result = await collection.methods.mint(owner).send({from: owner});
376 const tokenId = result.events.Transfer.returnValues.tokenId;376 const tokenId = result.events.Transfer.returnValues.tokenId;
377 await collection.methods.setTokenPropertyPermission('A', true, true, true).send({from: owner});377 await collection.methods.setTokenPropertyPermissions([['A', [[0, true], [1, true], [2, true]]]]).send({from: owner});
378378
379379
380 const ethEvents: any = [];380 const ethEvents: any = [];
modifiedtests/src/eth/tokenProperties.test.tsdiffbeforeafterboth
17import {IKeyringPair} from '@polkadot/types/types';17import {IKeyringPair} from '@polkadot/types/types';
18import {Contract} from 'web3-eth-contract';18import {Contract} from 'web3-eth-contract';
19import {itEth, usingEthPlaygrounds, expect} from './util';19import {itEth, usingEthPlaygrounds, expect} from './util';
20import {ITokenPropertyPermission} from '../util/playgrounds/types';20import {ITokenPropertyPermission, TCollectionMode} from '../util/playgrounds/types';
21import {Pallets} from '../util';21import {Pallets} from '../util';
22import {UniqueNFTCollection, UniqueNFToken, UniqueRFTCollection} from '../util/playgrounds/unique';22import {UniqueNFTCollection, UniqueNFToken, UniqueRFTCollection} from '../util/playgrounds/unique';
2323
32 });32 });
33 });33 });
3434
35 [
36 {mode: 'nft'},
37 {mode: 'rft'}
38 ].map(testCase =>
35 itEth('Can be reconfigured', async({helper}) => {39 itEth(`[${testCase.mode}] Set and get token property permissions`, async({helper}) => {
36 const owner = await helper.eth.createAccountWithBalance(donor);40 const owner = await helper.eth.createAccountWithBalance(donor);
37 const caller = await helper.eth.createAccountWithBalance(donor);41 const caller = await helper.ethCrossAccount.createAccountWithBalance(donor);
42 const mode: any = testCase.mode;
38 for(const [mutable,collectionAdmin, tokenOwner] of cartesian([], [false, true], [false, true], [false, true])) {43 for(const [mutable,collectionAdmin, tokenOwner] of cartesian([], [false, true], [false, true], [false, true])) {
39 const collection = await helper.nft.mintCollection(alice);44 const {collectionId, collectionAddress} = await helper.eth.createCollection(mode, owner, 'A', 'B', 'C');
40 await collection.addAdmin(alice, {Ethereum: caller});
41
42 const address = helper.ethAddress.fromCollectionId(collection.collectionId);45 const collection = await helper.ethNativeContract.collection(collectionAddress, mode, owner);
43 const contract = helper.ethNativeContract.collection(address, 'nft', caller);46 await collection.methods.addCollectionAdminCross(caller).send({from: owner});
44 47
45 await contract.methods.setTokenPropertyPermissions([['testKey', [[0, mutable], [1, tokenOwner], [2, collectionAdmin]]]]).send({from: caller});48 await collection.methods.setTokenPropertyPermissions([['testKey', [[0, mutable], [1, tokenOwner], [2, collectionAdmin]]]]).send({from: caller.eth});
46 49
47 expect(await collection.getPropertyPermissions()).to.be.deep.equal([{50 expect(await helper.nft.getPropertyPermissions(collectionId)).to.be.deep.equal([{
48 key: 'testKey',51 key: 'testKey',
49 permission: {mutable, collectionAdmin, tokenOwner},52 permission: {mutable, collectionAdmin, tokenOwner},
50 }]);53 }]);
5154
52 expect(await contract.methods.tokenPropertyPermissions().call({from: caller})).to.be.like([55 expect(await collection.methods.tokenPropertyPermissions().call({from: caller.eth})).to.be.like([
53 ['testKey', [['0', mutable], ['1', tokenOwner], ['2', collectionAdmin]]]56 ['testKey', [['0', mutable], ['1', tokenOwner], ['2', collectionAdmin]]]
54 ]);57 ]);
55 }58 }
56 });59 })
60 );
5761
58 [62 [
59 {63 {