difftreelog
Merge pull request #186 from UniqueNetwork/test/evm-marketplace
in: master
EVM matcher contract test
13 files changed
crates/evm-coder/tests/a.rsdiffbeforeafterboth223use evm_coder::{solidity_interface, types::*, ToLog, execution::Result};3use evm_coder::{solidity_interface, types::*, ToLog, execution::Result};4use evm_coder_macros::solidity;4use evm_coder_macros::solidity;5use std as sp_std;566struct Impls;7struct Impls;78pallets/nft/src/lib.rsdiffbeforeafterboth1399 item_id: TokenId,1399 item_id: TokenId,1400 amount: u128,1400 amount: u128,1401 ) -> DispatchResult {1401 ) -> DispatchResult {1402 if sender == from {1403 // Transfer by `from`, because it is either equal to sender, or derived from him1404 return Self::transfer_internal(from, recipient, collection, item_id, amount);1405 }14061402 // Check approval1407 // Check approval1403 collection.consume_sload()?;1408 collection.consume_sload()?;pallets/nft/src/mock.rsdiffbeforeafterboth129 fn as_sub(&self) -> &u64 {129 fn as_sub(&self) -> &u64 {130 &self.0130 &self.0131 }131 }132 fn from_eth(_eth: sp_core::H160) -> Self {132 fn from_eth(eth: sp_core::H160) -> Self {133 let mut sub_raw = [0; 8];134 sub_raw.copy_from_slice(ð.0[0..8]);135 let sub = u64::from_be_bytes(sub_raw);133 unimplemented!()136 Self(sub, eth)134 }137 }135 fn as_eth(&self) -> &sp_core::H160 {138 fn as_eth(&self) -> &sp_core::H160 {136 &self.1139 &self.1tests/package.jsondiffbeforeafterboth24 "lint": "eslint --ext .ts,.js src/",24 "lint": "eslint --ext .ts,.js src/",25 "fix": "eslint --ext .ts,.js src/ --fix",25 "fix": "eslint --ext .ts,.js src/ --fix",26 "test": "mocha --timeout 9999999 -r ts-node/register './**/*.test.ts'",26 "test": "mocha --timeout 9999999 -r ts-node/register './**/*.test.ts'",27 "testEth": "mocha --timeout 9999999 -r ts-node/register ./**/eth/**/*.test.ts",27 "testEth": "mocha --timeout 9999999 -r ts-node/register './**/eth/**/*.test.ts'",28 "load": "mocha --timeout 9999999 -r ts-node/register ./**/*.load.ts",28 "load": "mocha --timeout 9999999 -r ts-node/register './**/*.load.ts'",29 "loadTransfer": "ts-node src/transfer.nload.ts",29 "loadTransfer": "ts-node src/transfer.nload.ts",30 "testCollision": "mocha --timeout 9999999 -r ts-node/register ./src/collision-tests/*.test.ts",30 "testCollision": "mocha --timeout 9999999 -r ts-node/register ./src/collision-tests/*.test.ts",31 "testAddCollectionAdmin": "mocha --timeout 9999999 -r ts-node/register ./**/addCollectionAdmin.test.ts",31 "testAddCollectionAdmin": "mocha --timeout 9999999 -r ts-node/register ./**/addCollectionAdmin.test.ts",tests/src/eth/marketplace/MarketPlaceKSM.abidiffbeforeafterbothno changes
tests/src/eth/marketplace/MarketPlaceKSM.bindiffbeforeafterbothno changes
tests/src/eth/marketplace/MarketPlaceKSM.soldiffbeforeafterbothno changes
tests/src/eth/marketplace/MarketPlaceUNQ.abidiffbeforeafterbothno changes
tests/src/eth/marketplace/MarketPlaceUNQ.bindiffbeforeafterbothno changes
tests/src/eth/marketplace/MarketPlaceUNQ.soldiffbeforeafterbothno changes
tests/src/eth/marketplace/marketplace.test.tsdiffbeforeafterbothno changes
tests/src/eth/util/helpers.tsdiffbeforeafterboth143 return normalizeEvents(out);143 return normalizeEvents(out);144}144}145145146export function subToEth(eth: string): string {146export function subToEthLowercase(eth: string): string {147 const bytes = addressToEvm(eth);147 const bytes = addressToEvm(eth);148 const string = '0x' + Buffer.from(bytes).toString('hex');148 return '0x' + Buffer.from(bytes).toString('hex');149 return Web3.utils.toChecksumAddress(string);150}149}150151export function subToEth(eth: string): string {152 return Web3.utils.toChecksumAddress(subToEthLowercase(eth));153}151154152export function compileContract(name: string, src: string) {155export function compileContract(name: string, src: string) {153 const out = JSON.parse(solc.compile(JSON.stringify({156 const out = JSON.parse(solc.compile(JSON.stringify({236 return new web3.eth.Contract(contractHelpersAbi as any, '0x842899ECF380553E8a4de75bF534cdf6fBF64049', {from: caller, ...GAS_ARGS});239 return new web3.eth.Contract(contractHelpersAbi as any, '0x842899ECF380553E8a4de75bF534cdf6fBF64049', {from: caller, ...GAS_ARGS});237}240}241242export async function executeEthTxOnSub(api: ApiPromise, from: IKeyringPair, to: any, mkTx: (methods: any) => any, { value = 0 }: {value?: bigint | number} = { }) {243 const tx = api.tx.evm.call(244 subToEth(from.address),245 to.options.address,246 mkTx(to.methods).encodeABI(),247 value,248 GAS_ARGS.gas,249 GAS_ARGS.gasPrice,250 null,251 );252 const events = await submitTransactionAsync(from, tx);253 expect(events.find(({ event: {section, method}})=>section === 'evm' && method === 'Executed')).to.be.not.undefined;254}238255239export async function ethBalanceViaSub(api: ApiPromise, address: string): Promise<bigint> {256export async function ethBalanceViaSub(api: ApiPromise, address: string): Promise<bigint> {240 return (await getBalance(api, [evmToAddress(address)]))[0];257 return (await getBalance(api, [evmToAddress(address)]))[0];tests/src/util/helpers.tsdiffbeforeafterboth1169 });1169 });1170}1170}117111711172export async function queryNftOwner(api: ApiPromise, collectionId: number, tokenId: number): Promise<CrossAccountId> {1173 return normalizeAccountId((await api.query.nft.nftItemList(collectionId, tokenId) as any).toJSON().Owner);1174}