From 75d727efa2e16c3a452e847b52ef1f660fcc19a5 Mon Sep 17 00:00:00 2001 From: PraetorP Date: Tue, 06 Sep 2022 14:16:30 +0000 Subject: [PATCH] Merge branch 'feature/app-staking' of https://github.com/UniqueNetwork/unique-chain into feature/app-staking --- --- a/tests/src/eth/contractSponsoring.test.ts +++ b/tests/src/eth/contractSponsoring.test.ts @@ -15,6 +15,7 @@ // along with Unique Network. If not, see . import {expect} from 'chai'; +import { expectSubstrateEventsAtBlock } from '../util/helpers'; import { contractHelpers, createEthAccountWithBalance, @@ -43,8 +44,9 @@ const helpers = contractHelpers(web3, owner); const result = await helpers.methods.selfSponsoredEnable(flipper.options.address).send(); - const events = normalizeEvents(result.events); - expect(events).to.be.deep.equal([ + // console.log(result); + const ethEvents = normalizeEvents(result.events); + expect(ethEvents).to.be.deep.equal([ { address: flipper.options.address, event: 'ContractSponsorSet', @@ -62,6 +64,13 @@ }, }, ]); + + await expectSubstrateEventsAtBlock( + api, + result.blockNumber, + 'evmContractHelpers', + ['ContractSponsorSet','ContractSponsorshipConfirmed'], + ); }); itWeb3('Self sponsored can not be set by the address that did not deployed the contract', async ({api, web3, privateKeyWrapper}) => { @@ -121,6 +130,13 @@ }, }, ]); + + await expectSubstrateEventsAtBlock( + api, + result.blockNumber, + 'evmContractHelpers', + ['ContractSponsorSet'], + ); }); itWeb3('Sponsor can not be set by the address that did not deployed the contract', async ({api, web3, privateKeyWrapper}) => { @@ -163,6 +179,13 @@ }, }, ]); + + await expectSubstrateEventsAtBlock( + api, + result.blockNumber, + 'evmContractHelpers', + ['ContractSponsorshipConfirmed'], + ); }); itWeb3('Sponsorship can not be confirmed by the address that not pending as sponsor', async ({api, web3, privateKeyWrapper}) => { @@ -248,6 +271,13 @@ }, }, ]); + + await expectSubstrateEventsAtBlock( + api, + result.blockNumber, + 'evmContractHelpers', + ['ContractSponsorRemoved'], + ); }); itWeb3('Sponsor can not be removed by the address that did not deployed the contract', async ({api, web3, privateKeyWrapper}) => { --- a/tests/src/util/helpers.ts +++ b/tests/src/util/helpers.ts @@ -17,10 +17,11 @@ import '../interfaces/augment-api-rpc'; import '../interfaces/augment-api-query'; import {ApiPromise} from '@polkadot/api'; -import type {AccountId, EventRecord, Event} from '@polkadot/types/interfaces'; +import type {AccountId, EventRecord, Event, BlockNumber} from '@polkadot/types/interfaces'; import type {GenericEventData} from '@polkadot/types'; import {AnyTuple, IEvent, IKeyringPair} from '@polkadot/types/types'; import {evmToAddress} from '@polkadot/util-crypto'; +import {AnyNumber} from '@polkadot/types-codec/types'; import BN from 'bn.js'; import chai from 'chai'; import chaiAsPromised from 'chai-as-promised'; @@ -1780,3 +1781,23 @@ itApi.only = (name: string, cb: (apis: { api: ApiPromise, privateKeyWrapper: (account: string) => IKeyringPair }) => any) => itApi(name, cb, {only: true}); itApi.skip = (name: string, cb: (apis: { api: ApiPromise, privateKeyWrapper: (account: string) => IKeyringPair }) => any) => itApi(name, cb, {skip: true}); + + +export async function expectSubstrateEventsAtBlock(api: ApiPromise, blockNumber: AnyNumber | BlockNumber, section: string, methods: string[], dryRun = false) { + const blockHash = await api.rpc.chain.getBlockHash(blockNumber); + const subEvents = (await api.query.system.events.at(blockHash)) + .filter(x => x.event.section === section) + .map((x) => x.toHuman()); + const events = methods.map((m) => { + return { + event: { + method: m, + section, + }, + }; + }); + if (!dryRun) { + expect(subEvents).to.be.like(events); + } + return subEvents; +} \ No newline at end of file -- gitstuff