difftreelog
Merge branch 'feature/app-staking' of https://github.com/UniqueNetwork/unique-chain into feature/app-staking
in: master
2 files changed
tests/src/eth/contractSponsoring.test.tsdiffbeforeafterboth15// along with Unique Network. If not, see <http://www.gnu.org/licenses/>.15// along with Unique Network. If not, see <http://www.gnu.org/licenses/>.161617import {expect} from 'chai';17import {expect} from 'chai';18import { expectSubstrateEventsAtBlock } from '../util/helpers';18import {19import {19 contractHelpers,20 contractHelpers,20 createEthAccountWithBalance,21 createEthAccountWithBalance,43 const helpers = contractHelpers(web3, owner);44 const helpers = contractHelpers(web3, owner);44 45 45 const result = await helpers.methods.selfSponsoredEnable(flipper.options.address).send();46 const result = await helpers.methods.selfSponsoredEnable(flipper.options.address).send();47 // console.log(result);46 const events = normalizeEvents(result.events);48 const ethEvents = normalizeEvents(result.events);47 expect(events).to.be.deep.equal([49 expect(ethEvents).to.be.deep.equal([48 {50 {49 address: flipper.options.address,51 address: flipper.options.address,50 event: 'ContractSponsorSet',52 event: 'ContractSponsorSet',63 },65 },64 ]);66 ]);6768 await expectSubstrateEventsAtBlock(69 api, 70 result.blockNumber,71 'evmContractHelpers',72 ['ContractSponsorSet','ContractSponsorshipConfirmed'],73 );65 });74 });667567 itWeb3('Self sponsored can not be set by the address that did not deployed the contract', async ({api, web3, privateKeyWrapper}) => {76 itWeb3('Self sponsored can not be set by the address that did not deployed the contract', async ({api, web3, privateKeyWrapper}) => {122 },131 },123 ]);132 ]);133134 await expectSubstrateEventsAtBlock(135 api, 136 result.blockNumber,137 'evmContractHelpers',138 ['ContractSponsorSet'],139 );124 });140 });125 141 126 itWeb3('Sponsor can not be set by the address that did not deployed the contract', async ({api, web3, privateKeyWrapper}) => {142 itWeb3('Sponsor can not be set by the address that did not deployed the contract', async ({api, web3, privateKeyWrapper}) => {164 },180 },165 ]);181 ]);182183 await expectSubstrateEventsAtBlock(184 api, 185 result.blockNumber,186 'evmContractHelpers',187 ['ContractSponsorshipConfirmed'],188 );166 });189 });167190168 itWeb3('Sponsorship can not be confirmed by the address that not pending as sponsor', async ({api, web3, privateKeyWrapper}) => {191 itWeb3('Sponsorship can not be confirmed by the address that not pending as sponsor', async ({api, web3, privateKeyWrapper}) => {249 },272 },250 ]);273 ]);274275 await expectSubstrateEventsAtBlock(276 api, 277 result.blockNumber,278 'evmContractHelpers',279 ['ContractSponsorRemoved'],280 );251 });281 });252282253 itWeb3('Sponsor can not be removed by the address that did not deployed the contract', async ({api, web3, privateKeyWrapper}) => {283 itWeb3('Sponsor can not be removed by the address that did not deployed the contract', async ({api, web3, privateKeyWrapper}) => {tests/src/util/helpers.tsdiffbeforeafterboth17import '../interfaces/augment-api-rpc';17import '../interfaces/augment-api-rpc';18import '../interfaces/augment-api-query';18import '../interfaces/augment-api-query';19import {ApiPromise} from '@polkadot/api';19import {ApiPromise} from '@polkadot/api';20import type {AccountId, EventRecord, Event} from '@polkadot/types/interfaces';20import type {AccountId, EventRecord, Event, BlockNumber} from '@polkadot/types/interfaces';21import type {GenericEventData} from '@polkadot/types';21import type {GenericEventData} from '@polkadot/types';22import {AnyTuple, IEvent, IKeyringPair} from '@polkadot/types/types';22import {AnyTuple, IEvent, IKeyringPair} from '@polkadot/types/types';23import {evmToAddress} from '@polkadot/util-crypto';23import {evmToAddress} from '@polkadot/util-crypto';24import {AnyNumber} from '@polkadot/types-codec/types';24import BN from 'bn.js';25import BN from 'bn.js';25import chai from 'chai';26import chai from 'chai';26import chaiAsPromised from 'chai-as-promised';27import chaiAsPromised from 'chai-as-promised';1782itApi.skip = (name: string, cb: (apis: { api: ApiPromise, privateKeyWrapper: (account: string) => IKeyringPair }) => any) => itApi(name, cb, {skip: true});1783itApi.skip = (name: string, cb: (apis: { api: ApiPromise, privateKeyWrapper: (account: string) => IKeyringPair }) => any) => itApi(name, cb, {skip: true});1783178417851786export async function expectSubstrateEventsAtBlock(api: ApiPromise, blockNumber: AnyNumber | BlockNumber, section: string, methods: string[], dryRun = false) {1787 const blockHash = await api.rpc.chain.getBlockHash(blockNumber);1788 const subEvents = (await api.query.system.events.at(blockHash))1789 .filter(x => x.event.section === section)1790 .map((x) => x.toHuman());1791 const events = methods.map((m) => {1792 return {1793 event: {1794 method: m,1795 section,1796 },1797 };1798 });1799 if (!dryRun) {1800 expect(subEvents).to.be.like(events);1801 }1802 return subEvents;1803}