difftreelog
Add test for vesting pallet presence, cleanup other tests
in: master
12 files changed
Cargo.lockdiffbeforeafterboth1227source = "registry+https://github.com/rust-lang/crates.io-index"1227source = "registry+https://github.com/rust-lang/crates.io-index"1228checksum = "e78d4f1cc4ae33bbfc157ed5d5a5ef3bc29227303d595861deb238fcec4e9457"1228checksum = "e78d4f1cc4ae33bbfc157ed5d5a5ef3bc29227303d595861deb238fcec4e9457"12291230[[package]]1231name = "enumflags2"1232version = "0.6.4"1233source = "registry+https://github.com/rust-lang/crates.io-index"1234checksum = "83c8d82922337cd23a15f88b70d8e4ef5f11da38dd7cdb55e84dd5de99695da0"1235dependencies = [1236 "enumflags2_derive",1237]12381239[[package]]1240name = "enumflags2_derive"1241version = "0.6.4"1242source = "registry+https://github.com/rust-lang/crates.io-index"1243checksum = "946ee94e3dbf58fdd324f9ce245c7b238d46a66f00e86a020b71996349e46cce"1244dependencies = [1245 "proc-macro2",1246 "quote",1247 "syn",1248]122912491230[[package]]1250[[package]]1231name = "env_logger"1251name = "env_logger"3541 "pallet-transaction-payment",3561 "pallet-transaction-payment",3542 "pallet-transaction-payment-rpc-runtime-api",3562 "pallet-transaction-payment-rpc-runtime-api",3543 "pallet-treasury",3563 "pallet-treasury",3564 "pallet-vesting",3544 "parity-scale-codec",3565 "parity-scale-codec",3545 "serde",3566 "serde",3546 "sp-api",3567 "sp-api",4019 "sp-std",4040 "sp-std",4020]4041]40424043[[package]]4044name = "pallet-vesting"4045version = "2.0.0"4046source = "git+https://github.com/usetech-llc/substrate.git?branch=release_flexi#59646c902484d9c5e8933a80cbed551228b81274"4047dependencies = [4048 "enumflags2",4049 "frame-support",4050 "frame-system",4051 "parity-scale-codec",4052 "serde",4053 "sp-runtime",4054 "sp-std",4055]402140564022[[package]]4057[[package]]4023name = "parity-db"4058name = "parity-db"node/src/chain_spec.rsdiffbeforeafterboth155 }),155 }),156 pallet_treasury: Some(Default::default()),156 pallet_treasury: Some(Default::default()),157 pallet_sudo: Some(SudoConfig { key: root_key }),157 pallet_sudo: Some(SudoConfig { key: root_key }),158 pallet_vesting: Some(Default::default()),158 pallet_nft: Some(NftConfig {159 pallet_nft: Some(NftConfig {159 collection: vec![(160 collection: vec![(160 1,161 1,runtime/Cargo.tomldiffbeforeafterboth45pallet-timestamp = { default-features = false, version = '2.0.0' , git = 'https://github.com/usetech-llc/substrate.git', branch = 'release_flexi' }45pallet-timestamp = { default-features = false, version = '2.0.0' , git = 'https://github.com/usetech-llc/substrate.git', branch = 'release_flexi' }46pallet-transaction-payment = { default-features = false, version = '2.0.0' , git = 'https://github.com/usetech-llc/substrate.git', branch = 'release_flexi' }46pallet-transaction-payment = { default-features = false, version = '2.0.0' , git = 'https://github.com/usetech-llc/substrate.git', branch = 'release_flexi' }47pallet-transaction-payment-rpc-runtime-api = { default-features = false, version = '2.0.0' , git = 'https://github.com/usetech-llc/substrate.git', branch = 'release_flexi' }47pallet-transaction-payment-rpc-runtime-api = { default-features = false, version = '2.0.0' , git = 'https://github.com/usetech-llc/substrate.git', branch = 'release_flexi' }48pallet-treasury = { version = "2.0.0", default-features = false, git = 'https://github.com/usetech-llc/substrate.git', branch = 'release_flexi' }49pallet-vesting = { version = "2.0.0", default-features = false, git = 'https://github.com/usetech-llc/substrate.git', branch = 'release_flexi' }48sp-api = { default-features = false, version = '2.0.0' , git = 'https://github.com/usetech-llc/substrate.git', branch = 'release_flexi' }50sp-api = { default-features = false, version = '2.0.0' , git = 'https://github.com/usetech-llc/substrate.git', branch = 'release_flexi' }49sp-block-builder = { default-features = false, version = '2.0.0' , git = 'https://github.com/usetech-llc/substrate.git', branch = 'release_flexi' }51sp-block-builder = { default-features = false, version = '2.0.0' , git = 'https://github.com/usetech-llc/substrate.git', branch = 'release_flexi' }50sp-consensus-aura = { default-features = false, version = '0.8.0' , git = 'https://github.com/usetech-llc/substrate.git', branch = 'release_flexi' }52sp-consensus-aura = { default-features = false, version = '0.8.0' , git = 'https://github.com/usetech-llc/substrate.git', branch = 'release_flexi' }57sp-transaction-pool = { default-features = false, version = '2.0.0' , git = 'https://github.com/usetech-llc/substrate.git', branch = 'release_flexi' }59sp-transaction-pool = { default-features = false, version = '2.0.0' , git = 'https://github.com/usetech-llc/substrate.git', branch = 'release_flexi' }58sp-version = { default-features = false, version = '2.0.0' , git = 'https://github.com/usetech-llc/substrate.git', branch = 'release_flexi' }60sp-version = { default-features = false, version = '2.0.0' , git = 'https://github.com/usetech-llc/substrate.git', branch = 'release_flexi' }5960pallet-treasury = { version = "2.0.0", default-features = false, git = 'https://github.com/usetech-llc/substrate.git', branch = 'release_flexi' }616162[features]62[features]63default = ['std']63default = ['std']90 'pallet-timestamp/std',90 'pallet-timestamp/std',91 'pallet-transaction-payment/std',91 'pallet-transaction-payment/std',92 'pallet-transaction-payment-rpc-runtime-api/std',92 'pallet-transaction-payment-rpc-runtime-api/std',93 'pallet-treasury/std',94 'pallet-vesting/std',9593 'pallet-nft/std',96 'pallet-nft/std',94 'sp-api/std',97 'sp-api/std',103 'sp-transaction-pool/std',106 'sp-transaction-pool/std',104 'sp-version/std',107 'sp-version/std',105108106 'pallet-treasury/std',107]109]108110runtime/src/lib.rsdiffbeforeafterboth17use sp_runtime::{17use sp_runtime::{18 create_runtime_str, generic, impl_opaque_keys,18 create_runtime_str, generic, impl_opaque_keys,19 traits::{19 traits::{20 Convert, BlakeTwo256, Block as BlockT, IdentifyAccount, 20 Convert, ConvertInto, BlakeTwo256, Block as BlockT, IdentifyAccount, 21 IdentityLookup, NumberFor, Saturating, Verify,21 IdentityLookup, NumberFor, Saturating, Verify,22 },22 },23 transaction_validity::{TransactionSource, TransactionValidity},23 transaction_validity::{TransactionSource, TransactionValidity},412 type Call = Call;412 type Call = Call;413}413}414415parameter_types! {416 pub const MinVestedTransfer: Balance = 100 * DOLLARS;417}418419impl pallet_vesting::Trait for Runtime {420 type Event = Event;421 type Currency = Balances;422 type BlockNumberToBalance = ConvertInto;423 type MinVestedTransfer = MinVestedTransfer;424 type WeightInfo = ();425}414426415/// Used for the module nft in `./nft.rs`427/// Used for the module nft in `./nft.rs`416impl pallet_nft::Trait for Runtime {428impl pallet_nft::Trait for Runtime {435 Sudo: pallet_sudo::{Module, Call, Config<T>, Storage, Event<T>},447 Sudo: pallet_sudo::{Module, Call, Config<T>, Storage, Event<T>},436 Nft: pallet_nft::{Module, Call, Config<T>, Storage, Event<T>},448 Nft: pallet_nft::{Module, Call, Config<T>, Storage, Event<T>},437 Treasury: pallet_treasury::{Module, Call, Storage, Config, Event<T>},449 Treasury: pallet_treasury::{Module, Call, Storage, Config, Event<T>},450 Vesting: pallet_vesting::{Module, Call, Config<T>, Storage, Event<T>},438 }451 }439);452);440453tests/src/blocks-production.test.tsdiffbeforeafterboth2import promisifySubstrate from "./substrate/promisify-substrate";2import promisifySubstrate from "./substrate/promisify-substrate";3import { expect } from "chai";3import { expect } from "chai";445describe('Blocks Production', () => {5describe('Blocks Production smoke test', () => {6 it('Node produces new blocks', async () => {6 it('Node produces new blocks', async () => {7 await usingApi(async api => {7 await usingApi(async api => {8 const blocksPromise = promisifySubstrate(api, () => {8 const blocksPromise = promisifySubstrate(api, () => {tests/src/connection.test.tsdiffbeforeafterboth778const expect = chai.expect;8const expect = chai.expect;9910describe('Connection', () => {10describe('Connection smoke test', () => {11 it('Connection can be established', async () => {11 it('Connection can be established', async () => {12 await usingApi(async api => {12 await usingApi(async api => {13 const health = await api.rpc.system.health();13 const health = await api.rpc.system.health();16 });16 });171718 it('Cannot connect to 255.255.255.255', async () => {18 it('Cannot connect to 255.255.255.255', async () => {19 console.log = function () {};20 console.error = function () {};2119 const neverConnectProvider = new WsProvider('ws://255.255.255.255:9944');22 const neverConnectProvider = new WsProvider('ws://255.255.255.255:9944');20 await expect((async () => {23 await expect((async () => {23 }, { provider: neverConnectProvider });26 }, { provider: neverConnectProvider });24 })()).to.be.eventually.rejected;27 })()).to.be.eventually.rejected;2829 delete console.log;30 delete console.error;25 });31 });26});32});tests/src/contracts.test.tsdiffbeforeafterboth1import { ApiPromise } from "@polkadot/api";1import { expect } from "chai";2import { expect } from "chai";2import usingApi from "./substrate/substrate-api";3import { default as usingApi, submitTransactionAsync } from "./substrate/substrate-api";3import fs from "fs";4import fs from "fs";4import { Abi, BlueprintPromise, CodePromise } from "@polkadot/api-contract";5import { Abi, BlueprintPromise, CodePromise } from "@polkadot/api-contract";5import { IKeyringPair } from "@polkadot/types/types";6import { IKeyringPair } from "@polkadot/types/types";6import { Keyring } from "@polkadot/api";7import { Keyring } from "@polkadot/api";7import { ApiTypes, SubmittableExtrinsic } from "@polkadot/api/types";8import { ApiTypes, SubmittableExtrinsic } from "@polkadot/api/types";9import { BigNumber } from 'bignumber.js';10import { findUnusedAddress } from './util/helpers'8119const value = 0;12const value = 0;10const gasLimit = 3000n * 1000000n;13const gasLimit = 3000n * 1000000n;14const endowment = `1000000000000000`;111512function deployBlueprint(alice: IKeyringPair, code: CodePromise): Promise<BlueprintPromise> {16function deployBlueprint(alice: IKeyringPair, code: CodePromise): Promise<BlueprintPromise> {13 return new Promise<BlueprintPromise>(async (resolve, reject) => {17 return new Promise<BlueprintPromise>(async (resolve, reject) => {252926function deployContract(alice: IKeyringPair, blueprint: BlueprintPromise) : Promise<any> {30function deployContract(alice: IKeyringPair, blueprint: BlueprintPromise) : Promise<any> {27 return new Promise<any>(async (resolve, reject) => {31 return new Promise<any>(async (resolve, reject) => {28 const endowment = 1000000000000000n;29 const initValue = true;32 const initValue = true;303331 const unsub = await blueprint.tx34 const unsub = await blueprint.tx39 });42 });40}43}414442function runTransaction(privateKey: IKeyringPair, extrinsic: SubmittableExtrinsic<ApiTypes>) {45async function prepareDeployer(api: ApiPromise) {43 return new Promise<void>(async (resolve, reject) => {46 // Find unused address47 const deployer = await findUnusedAddress(api);4849 // Transfer balance to it50 const keyring = new Keyring({ type: 'sr25519' });51 const alice = keyring.addFromUri(`//Alice`);52 let amount = new BigNumber(endowment);53 amount = amount.plus(1e15);44 extrinsic.signAndSend(privateKey, async result => {54 const tx = api.tx.balances.transfer(deployer.address, amount.toFixed());45 if(!result.isInBlock) {55 await submitTransactionAsync(alice, tx);46 return;5647 }57 return deployer;4858}49 if(result.findRecord('system', 'ExtrinsicSuccess')) {50 resolve();51 }52 else {53 reject('Failed to flip value.');54 }55 })56 });57}585959describe('Contracts', () => {60describe('Contracts smoke test', () => {60 it(`Can deploy smart contract Flipper, instantiate it and call it's get and flip messages.`, async () => {61 it(`Can deploy smart contract Flipper, instantiate it and call it's get and flip messages.`, async () => {61 await usingApi(async api => {62 await usingApi(async api => {62 const keyring = new Keyring({ type: 'sr25519' });63 const alice = keyring.addFromUri("//Alice");63 const deployer = await prepareDeployer(api);64 64 65 const wasm = fs.readFileSync('./src/flipper/flipper.wasm');65 const wasm = fs.readFileSync('./src/flipper/flipper.wasm');66 66 696970 const code = new CodePromise(api, abi, wasm);70 const code = new CodePromise(api, abi, wasm);717172 const blueprint = await deployBlueprint(alice, code);72 const blueprint = await deployBlueprint(deployer, code);73 const contract = (await deployContract(alice, blueprint))['contract'];73 const contract = (await deployContract(deployer, blueprint))['contract'];747475 const getFlipValue = async () => {75 const getFlipValue = async () => {76 const result = await contract.query.get(alice.address, value, gasLimit);76 const result = await contract.query.get(deployer.address, value, gasLimit);777778 if(!result.result.isSuccess) {78 if(!result.result.isSuccess) {79 throw `Failed to get flipper value`;79 throw `Failed to get flipper value`;85 expect(initialGetResponse).to.be.true;85 expect(initialGetResponse).to.be.true;868687 const flip = contract.exec('flip', value, gasLimit);87 const flip = contract.exec('flip', value, gasLimit);88 await runTransaction(alice, flip);88 await submitTransactionAsync(deployer, flip);898990 const afterFlipGetResponse = await getFlipValue();90 const afterFlipGetResponse = await getFlipValue();9191112 // const bob = new GenericAccountId(api.registry, bobsPublicKey);112 // const bob = new GenericAccountId(api.registry, bobsPublicKey);113113114 // const transfer = contractInstance.exec('balance_transfer', 0, 1000000000000n, [bob, new u128(api.registry, 1000000)]);114 // const transfer = contractInstance.exec('balance_transfer', 0, 1000000000000n, [bob, new u128(api.registry, 1000000)]);115 // await runTransaction(alicesPrivateKey, transfer);115 // await submitTransactionAsync(alicesPrivateKey, transfer);116116117 // const [alicesBalanceAfter, bobsBalanceAfter] = await getBalance(api, [alicesPublicKey, bobsPublicKey]);117 // const [alicesBalanceAfter, bobsBalanceAfter] = await getBalance(api, [alicesPublicKey, bobsPublicKey]);118118tests/src/creditFeesToTreasury.test.tsdiffbeforeafterbothno changes
tests/src/crefitFeesToTreasury.test.tsdiffbeforeafterbothno changes
tests/src/pallet-presence.test.tsdiffbeforeafterboth6 return api.runtimeMetadata.asLatest.modules.map(m => m.name.toString().toLowerCase());6 return api.runtimeMetadata.asLatest.modules.map(m => m.name.toString().toLowerCase());7}7}89// Pallets that must always be present10const requiredPallets = [11 'nft', 'balances', 'contracts', 'randomnesscollectiveflip', 'system', 'timestamp', 'transactionpayment', 'treasury', 'vesting'12];1314// Pallets that depend on consensus and governance configuration15const consensusPallets = [16 'sudo', 'grandpa', 'aura'17];8189describe('Pallet presence.', () => {19describe('Pallet presence', () => {10 it('NFT pallet is present.', async () => {20 it('Required pallets are present', async () => {11 await usingApi(async api => {21 await usingApi(async api => {22 for (let i=0; i<requiredPallets.length; i++) {12 expect(getModuleNames(api)).to.include('nft');23 expect(getModuleNames(api)).to.include(requiredPallets[i]);24 }13 });25 });14 });26 });15 it('Balances pallet is present.', async () => {27 it('Governance and consensus pallets are present', async () => {16 await usingApi(async api => {28 await usingApi(async api => {29 for (let i=0; i<consensusPallets.length; i++) {17 expect(getModuleNames(api)).to.include('balances');30 expect(getModuleNames(api)).to.include(consensusPallets[i]);31 }18 });32 });19 });33 });20 it('Contracts pallet is present.', async () => {34 it('No extra pallets are included', async () => {21 await usingApi(async api => {35 await usingApi(async api => {22 expect(getModuleNames(api)).to.include('contracts');36 expect(getModuleNames(api).length).to.be.equal(requiredPallets.length + consensusPallets.length);23 });37 });24 });38 });25});39});tests/src/transfer.test.tsdiffbeforeafterboth3import { alicesPublicKey, bobsPublicKey, ferdiesPublicKey } from "./accounts";3import { alicesPublicKey, bobsPublicKey, ferdiesPublicKey } from "./accounts";4import privateKey from "./substrate/privateKey";4import privateKey from "./substrate/privateKey";5import getBalance from "./substrate/get-balance";5import getBalance from "./substrate/get-balance";6import { BigNumber } from 'bignumber.js';7import { findUnusedAddress } from './util/helpers'687describe('Transfer', () => {9describe('Transfer', () => {8 it('Balance transfers', async () => {10 it('Balance transfers', async () => {232524 it('Inability to pay fees error message is correct', async () => {26 it('Inability to pay fees error message is correct', async () => {25 await usingApi(async api => {27 await usingApi(async api => {28 // Find unused address26 const pk = privateKey('//Ferdie');29 const pk = await findUnusedAddress(api);273028 console.log = function () {};31 console.log = function () {};29 console.error = function () {};32 console.error = function () {};tests/src/util/helpers.tsdiffbeforeafterboth1import chai from 'chai';1import chai from 'chai';2import chaiAsPromised from 'chai-as-promised';2import chaiAsPromised from 'chai-as-promised';3import type { EventRecord } from '@polkadot/types/interfaces';3import type { AccountId, EventRecord } from '@polkadot/types/interfaces';4import { ApiPromise, Keyring } from "@polkadot/api";4import { default as usingApi, submitTransactionAsync } from "../substrate/substrate-api";5import { default as usingApi, submitTransactionAsync } from "../substrate/substrate-api";5import privateKey from '../substrate/privateKey';6import privateKey from '../substrate/privateKey';6import { alicesPublicKey } from "../accounts";7import { alicesPublicKey } from "../accounts";7import { strToUTF16, utf16ToStr, hexToStr } from '../util/util';8import { strToUTF16, utf16ToStr, hexToStr } from '../util/util';9import { IKeyringPair } from "@polkadot/types/types";10import { BigNumber } from 'bignumber.js';8119chai.use(chaiAsPromised);12chai.use(chaiAsPromised);10const expect = chai.expect;13const expect = chai.expect;98 });101 });99}102}100 103 101104export async function findUnusedAddress(api: ApiPromise): Promise<IKeyringPair> {105 let bal = new BigNumber(0);106 let unused;107 do {108 const randomSeed = 'seed' + Math.floor(Math.random() * Math.floor(10000));109 const keyring = new Keyring({ type: 'sr25519' });110 unused = keyring.addFromUri(`//${randomSeed}`);111 bal = new BigNumber((await api.query.system.account(unused.address)).data.free.toString());112 } while (bal.toFixed() != '0');113 return unused; 114}