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.tsdiffbeforeafterboth--- 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