git.delta.rocks / unique-network / refs/commits / 3f089fc34b06

difftreelog

refactor EthCrossAccount impl, signature some evm methods, tests and stubs

PraetorP2022-12-14parent: #1f3c059.patch.diff
in: master

16 files changed

modifiedpallets/common/src/erc.rsdiffbeforeafterboth
36use crate::{36use crate::{
37 Pallet, CollectionHandle, Config, CollectionProperties, SelfWeightOf,37 Pallet, CollectionHandle, Config, CollectionProperties, SelfWeightOf,
38 eth::{38 eth::{
39 EthCrossAccount, convert_cross_account_to_uint256, CollectionPermissions as EvmPermissions,39 EthCrossAccount, CollectionPermissions as EvmPermissions,
40 CollectionLimits as EvmCollectionLimits,40 CollectionLimits as EvmCollectionLimits,
41 },41 },
42 weights::WeightInfo,42 weights::WeightInfo,
modifiedpallets/common/src/eth.rsdiffbeforeafterboth
53 address[0..16] == ETH_COLLECTION_PREFIX53 address[0..16] == ETH_COLLECTION_PREFIX
54}54}
55
56/// Convert `CrossAccountId` to `uint256`.
57pub fn convert_cross_account_to_uint256<T: Config>(from: &T::CrossAccountId) -> uint256
58where
59 T::AccountId: AsRef<[u8; 32]>,
60{
61 let slice = from.as_sub().as_ref();
62 uint256::from_big_endian(slice)
63}
6455
65/// Convert `uint256` to `CrossAccountId`.56/// Convert `uint256` to `CrossAccountId`.
66pub fn convert_uint256_to_cross_account<T: Config>(from: uint256) -> T::CrossAccountId57pub fn convert_uint256_to_cross_account<T: Config>(from: uint256) -> T::CrossAccountId
73 T::CrossAccountId::from_sub(account_id)64 T::CrossAccountId::from_sub(account_id)
74}65}
75
76/// Convert `CrossAccountId` to `(address, uint256)`.
77pub fn convert_cross_account_to_tuple<T: Config>(
78 cross_account_id: &T::CrossAccountId,
79) -> (address, uint256)
80where
81 T::AccountId: AsRef<[u8; 32]>,
82{
83 if cross_account_id.is_canonical_substrate() {
84 let sub = convert_cross_account_to_uint256::<T>(cross_account_id);
85 (Default::default(), sub)
86 } else {
87 let eth = *cross_account_id.as_eth();
88 (eth, Default::default())
89 }
90}
9166
92/// Convert tuple `(address, uint256)` to `CrossAccountId`.67/// Convert tuple `(address, uint256)` to `CrossAccountId`.
93///68///
128 T::AccountId: AsRef<[u8; 32]>,103 T::AccountId: AsRef<[u8; 32]>,
129 {104 {
130 if cross_account_id.is_canonical_substrate() {105 if cross_account_id.is_canonical_substrate() {
131 Self {106 Self::from_sub::<T>(cross_account_id.as_sub())
132 eth: Default::default(),
133 sub: convert_cross_account_to_uint256::<T>(cross_account_id),
134 }
135 } else {107 } else {
136 Self {108 Self {
137 eth: *cross_account_id.as_eth(),109 eth: *cross_account_id.as_eth(),
modifiedpallets/evm-contract-helpers/Cargo.tomldiffbeforeafterboth
50 "pallet-evm-coder-substrate/std",50 "pallet-evm-coder-substrate/std",
51 "pallet-evm/std",51 "pallet-evm/std",
52 "up-sponsorship/std",52 "up-sponsorship/std",
53 "pallet-common/std",
53]54]
54try-runtime = ["frame-support/try-runtime"]55try-runtime = ["frame-support/try-runtime"]
55stubgen = ["evm-coder/stubgen"]56stubgen = ["evm-coder/stubgen", "pallet-common/stubgen"]
5657
modifiedpallets/evm-contract-helpers/src/eth.rsdiffbeforeafterboth
175 ///175 ///
176 /// @param contractAddress The contract for which a sponsor is requested.176 /// @param contractAddress The contract for which a sponsor is requested.
177 /// @return Tuble with sponsor address and his substrate mirror. If there is no confirmed sponsor error "Contract has no sponsor" throw.177 /// @return Tuble with sponsor address and his substrate mirror. If there is no confirmed sponsor error "Contract has no sponsor" throw.
178 fn sponsor(&self, contract_address: address) -> Result<(address, uint256)> {178 fn sponsor(&self, contract_address: address) -> Result<EthCrossAccount> {
179 let sponsor =179 Ok(EthCrossAccount::from_sub_cross_account::<T>(
180 Pallet::<T>::get_sponsor(contract_address).ok_or("Contract has no sponsor")?;180 &Pallet::<T>::get_sponsor(contract_address).ok_or("Contract has no sponsor")?,
181 Ok(pallet_common::eth::convert_cross_account_to_tuple::<T>(181 ))
182 &sponsor,
183 ))
184 }182 }
185 // fn sponsor(&self, contract_address: address) -> Result<EthCrossAccount> {
186 // Ok(EthCrossAccount::from_sub_cross_account::<T>(
187 // &Pallet::<T>::get_sponsor(contract_address).ok_or("Contract has no sponsor")?,
188 // ))
189 // }
190183
191 /// Check tat contract has confirmed sponsor.184 /// Check tat contract has confirmed sponsor.
192 ///185 ///
modifiedpallets/evm-contract-helpers/src/stubs/ContractHelpers.rawdiffbeforeafterboth

binary blob — no preview

modifiedpallets/evm-contract-helpers/src/stubs/ContractHelpers.soldiffbeforeafterboth
96 /// @return Tuble with sponsor address and his substrate mirror. If there is no confirmed sponsor error "Contract has no sponsor" throw.96 /// @return Tuble with sponsor address and his substrate mirror. If there is no confirmed sponsor error "Contract has no sponsor" throw.
97 /// @dev EVM selector for this function is: 0x766c4f37,97 /// @dev EVM selector for this function is: 0x766c4f37,
98 /// or in textual repr: sponsor(address)98 /// or in textual repr: sponsor(address)
99 function sponsor(address contractAddress) public view returns (Tuple0 memory) {99 function sponsor(address contractAddress) public view returns (EthCrossAccount memory) {
100 require(false, stub_error);100 require(false, stub_error);
101 contractAddress;101 contractAddress;
102 dummy;102 dummy;
103 return Tuple0(0x0000000000000000000000000000000000000000, 0);103 return EthCrossAccount(0x0000000000000000000000000000000000000000, 0);
104 }104 }
105105
106 /// Check tat contract has confirmed sponsor.106 /// Check tat contract has confirmed sponsor.
265 }265 }
266}266}
267267
268/// @dev anonymous struct268/// @dev Cross account struct
269struct Tuple0 {269struct EthCrossAccount {
270 address field_0;270 address eth;
271 uint256 field_1;271 uint256 sub;
272}272}
273273
modifiedpallets/nonfungible/src/erc.rsdiffbeforeafterboth
605 Ok(false)605 Ok(false)
606 }606 }
607607
608 /// @notice Function to mint token.608 /// @notice Function to a mint token.
609 /// @param to The new owner609 /// @param to The new owner
610 /// @return uint256 The id of the newly minted token610 /// @return uint256 The id of the newly minted token
611 #[weight(<SelfWeightOf<T>>::create_item())]611 #[weight(<SelfWeightOf<T>>::create_item())]
618 Ok(token_id)618 Ok(token_id)
619 }619 }
620620
621 /// @notice Function to mint token.621 /// @notice Function to a mint token.
622 /// @dev `tokenId` should be obtained with `nextTokenId` method,622 /// @dev `tokenId` should be obtained with `nextTokenId` method,
623 /// unlike standard, you can't specify it manually623 /// unlike standard, you can't specify it manually
624 /// @param to The new owner624 /// @param to The new owner
1070 Ok(true)1070 Ok(true)
1071 }1071 }
10721072
1073 /// @notice Function to mint token.1073 /// @notice Function to a mint token.
1074 /// @param to The new owner crossAccountId1074 /// @param to The new owner crossAccountId
1075 /// @param properties Properties of minted token1075 /// @param properties Properties of minted token
1076 /// @return uint256 The id of the newly minted token1076 /// @return uint256 The id of the newly minted token
modifiedpallets/nonfungible/src/stubs/UniqueNFT.soldiffbeforeafterboth
738 return false;738 return false;
739 }739 }
740740
741 /// @notice Function to mint token.741 /// @notice Function to a mint token.
742 /// @param to The new owner742 /// @param to The new owner
743 /// @return uint256 The id of the newly minted token743 /// @return uint256 The id of the newly minted token
744 /// @dev EVM selector for this function is: 0x6a627842,744 /// @dev EVM selector for this function is: 0x6a627842,
750 return 0;750 return 0;
751 }751 }
752752
753 // /// @notice Function to mint token.753 // /// @notice Function to a mint token.
754 // /// @dev `tokenId` should be obtained with `nextTokenId` method,754 // /// @dev `tokenId` should be obtained with `nextTokenId` method,
755 // /// unlike standard, you can't specify it manually755 // /// unlike standard, you can't specify it manually
756 // /// @param to The new owner756 // /// @param to The new owner
995 // return false;995 // return false;
996 // }996 // }
997997
998 /// @notice Function to mint token.998 /// @notice Function to a mint token.
999 /// @param to The new owner crossAccountId999 /// @param to The new owner crossAccountId
1000 /// @param properties Properties of minted token1000 /// @param properties Properties of minted token
1001 /// @return uint256 The id of the newly minted token1001 /// @return uint256 The id of the newly minted token
modifiedpallets/refungible/src/erc.rsdiffbeforeafterboth
637 Ok(false)637 Ok(false)
638 }638 }
639639
640 /// @notice Function to mint token.640 /// @notice Function to a mint token.
641 /// @param to The new owner641 /// @param to The new owner
642 /// @return uint256 The id of the newly minted token642 /// @return uint256 The id of the newly minted token
643 #[weight(<SelfWeightOf<T>>::create_item())]643 #[weight(<SelfWeightOf<T>>::create_item())]
650 Ok(token_id)650 Ok(token_id)
651 }651 }
652652
653 /// @notice Function to mint token.653 /// @notice Function to a mint token.
654 /// @dev `tokenId` should be obtained with `nextTokenId` method,654 /// @dev `tokenId` should be obtained with `nextTokenId` method,
655 /// unlike standard, you can't specify it manually655 /// unlike standard, you can't specify it manually
656 /// @param to The new owner656 /// @param to The new owner
1120 Ok(true)1120 Ok(true)
1121 }1121 }
11221122
1123 /// @notice Function to mint token.1123 /// @notice Function to a mint token.
1124 /// @param to The new owner crossAccountId1124 /// @param to The new owner crossAccountId
1125 /// @param properties Properties of minted token1125 /// @param properties Properties of minted token
1126 /// @return uint256 The id of the newly minted token1126 /// @return uint256 The id of the newly minted token
modifiedpallets/refungible/src/stubs/UniqueRefungible.soldiffbeforeafterboth
733 return false;733 return false;
734 }734 }
735735
736 /// @notice Function to mint token.736 /// @notice Function to a mint token.
737 /// @param to The new owner737 /// @param to The new owner
738 /// @return uint256 The id of the newly minted token738 /// @return uint256 The id of the newly minted token
739 /// @dev EVM selector for this function is: 0x6a627842,739 /// @dev EVM selector for this function is: 0x6a627842,
745 return 0;745 return 0;
746 }746 }
747747
748 // /// @notice Function to mint token.748 // /// @notice Function to a mint token.
749 // /// @dev `tokenId` should be obtained with `nextTokenId` method,749 // /// @dev `tokenId` should be obtained with `nextTokenId` method,
750 // /// unlike standard, you can't specify it manually750 // /// unlike standard, you can't specify it manually
751 // /// @param to The new owner751 // /// @param to The new owner
979 // return false;979 // return false;
980 // }980 // }
981981
982 /// @notice Function to mint token.982 /// @notice Function to a mint token.
983 /// @param to The new owner crossAccountId983 /// @param to The new owner crossAccountId
984 /// @param properties Properties of minted token984 /// @param properties Properties of minted token
985 /// @return uint256 The id of the newly minted token985 /// @return uint256 The id of the newly minted token
modifiedtests/src/eth/abi/contractHelpers.jsondiffbeforeafterboth
223 "outputs": [223 "outputs": [
224 {224 {
225 "components": [225 "components": [
226 { "internalType": "address", "name": "field_0", "type": "address" },226 { "internalType": "address", "name": "eth", "type": "address" },
227 { "internalType": "uint256", "name": "field_1", "type": "uint256" }227 { "internalType": "uint256", "name": "sub", "type": "uint256" }
228 ],228 ],
229 "internalType": "struct Tuple0",229 "internalType": "struct EthCrossAccount",
230 "name": "",230 "name": "",
231 "type": "tuple"231 "type": "tuple"
232 }232 }
modifiedtests/src/eth/api/ContractHelpers.soldiffbeforeafterboth
69 /// @return Tuble with sponsor address and his substrate mirror. If there is no confirmed sponsor error "Contract has no sponsor" throw.69 /// @return Tuble with sponsor address and his substrate mirror. If there is no confirmed sponsor error "Contract has no sponsor" throw.
70 /// @dev EVM selector for this function is: 0x766c4f37,70 /// @dev EVM selector for this function is: 0x766c4f37,
71 /// or in textual repr: sponsor(address)71 /// or in textual repr: sponsor(address)
72 function sponsor(address contractAddress) external view returns (Tuple0 memory);72 function sponsor(address contractAddress) external view returns (EthCrossAccount memory);
7373
74 /// Check tat contract has confirmed sponsor.74 /// Check tat contract has confirmed sponsor.
75 ///75 ///
171 function toggleAllowlist(address contractAddress, bool enabled) external;171 function toggleAllowlist(address contractAddress, bool enabled) external;
172}172}
173173
174/// @dev anonymous struct174/// @dev Cross account struct
175struct Tuple0 {175struct EthCrossAccount {
176 address field_0;176 address eth;
177 uint256 field_1;177 uint256 sub;
178}178}
179179
modifiedtests/src/eth/api/UniqueNFT.soldiffbeforeafterboth
515 /// or in textual repr: mintingFinished()515 /// or in textual repr: mintingFinished()
516 function mintingFinished() external view returns (bool);516 function mintingFinished() external view returns (bool);
517517
518 /// @notice Function to mint token.518 /// @notice Function to a mint token.
519 /// @param to The new owner519 /// @param to The new owner
520 /// @return uint256 The id of the newly minted token520 /// @return uint256 The id of the newly minted token
521 /// @dev EVM selector for this function is: 0x6a627842,521 /// @dev EVM selector for this function is: 0x6a627842,
522 /// or in textual repr: mint(address)522 /// or in textual repr: mint(address)
523 function mint(address to) external returns (uint256);523 function mint(address to) external returns (uint256);
524524
525 // /// @notice Function to mint token.525 // /// @notice Function to a mint token.
526 // /// @dev `tokenId` should be obtained with `nextTokenId` method,526 // /// @dev `tokenId` should be obtained with `nextTokenId` method,
527 // /// unlike standard, you can't specify it manually527 // /// unlike standard, you can't specify it manually
528 // /// @param to The new owner528 // /// @param to The new owner
674 // /// or in textual repr: mintBulkWithTokenURI(address,(uint256,string)[])674 // /// or in textual repr: mintBulkWithTokenURI(address,(uint256,string)[])
675 // function mintBulkWithTokenURI(address to, Tuple13[] memory tokens) external returns (bool);675 // function mintBulkWithTokenURI(address to, Tuple13[] memory tokens) external returns (bool);
676676
677 /// @notice Function to mint token.677 /// @notice Function to a mint token.
678 /// @param to The new owner crossAccountId678 /// @param to The new owner crossAccountId
679 /// @param properties Properties of minted token679 /// @param properties Properties of minted token
680 /// @return uint256 The id of the newly minted token680 /// @return uint256 The id of the newly minted token
modifiedtests/src/eth/api/UniqueRefungible.soldiffbeforeafterboth
513 /// or in textual repr: mintingFinished()513 /// or in textual repr: mintingFinished()
514 function mintingFinished() external view returns (bool);514 function mintingFinished() external view returns (bool);
515515
516 /// @notice Function to mint token.516 /// @notice Function to a mint token.
517 /// @param to The new owner517 /// @param to The new owner
518 /// @return uint256 The id of the newly minted token518 /// @return uint256 The id of the newly minted token
519 /// @dev EVM selector for this function is: 0x6a627842,519 /// @dev EVM selector for this function is: 0x6a627842,
520 /// or in textual repr: mint(address)520 /// or in textual repr: mint(address)
521 function mint(address to) external returns (uint256);521 function mint(address to) external returns (uint256);
522522
523 // /// @notice Function to mint token.523 // /// @notice Function to a mint token.
524 // /// @dev `tokenId` should be obtained with `nextTokenId` method,524 // /// @dev `tokenId` should be obtained with `nextTokenId` method,
525 // /// unlike standard, you can't specify it manually525 // /// unlike standard, you can't specify it manually
526 // /// @param to The new owner526 // /// @param to The new owner
666 // /// or in textual repr: mintBulkWithTokenURI(address,(uint256,string)[])666 // /// or in textual repr: mintBulkWithTokenURI(address,(uint256,string)[])
667 // function mintBulkWithTokenURI(address to, Tuple12[] memory tokens) external returns (bool);667 // function mintBulkWithTokenURI(address to, Tuple12[] memory tokens) external returns (bool);
668668
669 /// @notice Function to mint token.669 /// @notice Function to a mint token.
670 /// @param to The new owner crossAccountId670 /// @param to The new owner crossAccountId
671 /// @param properties Properties of minted token671 /// @param properties Properties of minted token
672 /// @return uint256 The id of the newly minted token672 /// @return uint256 The id of the newly minted token
modifiedtests/src/eth/nonFungible.test.tsdiffbeforeafterboth
17import {itEth, usingEthPlaygrounds, expect, EthUniqueHelper} from './util';17import {itEth, usingEthPlaygrounds, expect, EthUniqueHelper} from './util';
18import {IKeyringPair} from '@polkadot/types/types';18import {IKeyringPair} from '@polkadot/types/types';
19import {Contract} from 'web3-eth-contract';19import {Contract} from 'web3-eth-contract';
20import exp from 'constants';
21import {ITokenPropertyPermission} from '../util/playgrounds/types';20import {ITokenPropertyPermission} from '../util/playgrounds/types';
2221
2322
198 let tokenId = result.events.Transfer.returnValues.tokenId;204 let tokenId = result.events.Transfer.returnValues.tokenId;
199 expect(tokenId).to.be.equal(expectedTokenId);205 expect(tokenId).to.be.equal(expectedTokenId);
200206
201 const event = result.events.Transfer;207 let event = result.events.Transfer;
202 expect(event.address).to.be.equal(collectionAddress);208 expect(event.address).to.be.equal(collectionAddress);
203 expect(event.returnValues.from).to.be.equal('0x0000000000000000000000000000000000000000');209 expect(event.returnValues.from).to.be.equal('0x0000000000000000000000000000000000000000');
204 expect(event.returnValues.to).to.be.equal(helper.address.substrateToEth(bob.address));210 expect(event.returnValues.to).to.be.equal(helper.address.substrateToEth(bob.address));
205 expect(await contract.methods.properties(tokenId, []).call()).to.be.like([]);211 expect(await contract.methods.properties(tokenId, []).call()).to.be.like([]);
206 212
207 expectedTokenId = await contract.methods.nextTokenId().call();213 expectedTokenId = await contract.methods.nextTokenId().call();
208 result = await contract.methods.mintCross(receiverCross, properties).send();214 result = await contract.methods.mintCross(receiverCross, properties).send();
215 event = result.events.Transfer;
216 expect(event.address).to.be.equal(collectionAddress);
217 expect(event.returnValues.from).to.be.equal('0x0000000000000000000000000000000000000000');
218 expect(event.returnValues.to).to.be.equal(helper.address.substrateToEth(bob.address));
219 expect(await contract.methods.properties(tokenId, []).call()).to.be.like([]);
220
209 tokenId = result.events.Transfer.returnValues.tokenId;221 tokenId = result.events.Transfer.returnValues.tokenId;
210222
modifiedtests/src/eth/reFungible.test.tsdiffbeforeafterboth
159 let tokenId = result.events.Transfer.returnValues.tokenId;159 let tokenId = result.events.Transfer.returnValues.tokenId;
160 expect(tokenId).to.be.equal(expectedTokenId);160 expect(tokenId).to.be.equal(expectedTokenId);
161161
162 const event = result.events.Transfer;162 let event = result.events.Transfer;
163 expect(event.address).to.be.equal(collectionAddress);163 expect(event.address).to.be.equal(collectionAddress);
164 expect(event.returnValues.from).to.be.equal('0x0000000000000000000000000000000000000000');164 expect(event.returnValues.from).to.be.equal('0x0000000000000000000000000000000000000000');
165 expect(event.returnValues.to).to.be.equal(helper.address.substrateToEth(bob.address));165 expect(event.returnValues.to).to.be.equal(helper.address.substrateToEth(bob.address));
166 expect(await contract.methods.properties(tokenId, []).call()).to.be.like([]);166 expect(await contract.methods.properties(tokenId, []).call()).to.be.like([]);
167 167
168 expectedTokenId = await contract.methods.nextTokenId().call();168 expectedTokenId = await contract.methods.nextTokenId().call();
169 result = await contract.methods.mintCross(receiverCross, properties).send();169 result = await contract.methods.mintCross(receiverCross, properties).send();
170 event = result.events.Transfer;
171 expect(event.address).to.be.equal(collectionAddress);
172 expect(event.returnValues.from).to.be.equal('0x0000000000000000000000000000000000000000');
173 expect(event.returnValues.to).to.be.equal(helper.address.substrateToEth(bob.address));
174 expect(await contract.methods.properties(tokenId, []).call()).to.be.like([]);
175
170 tokenId = result.events.Transfer.returnValues.tokenId;176 tokenId = result.events.Transfer.returnValues.tokenId;
171177