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.tsdiffbeforeafterboth--- 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 <http://www.gnu.org/licenses/>.
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}) => {
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}