difftreelog
Update tests to pass on updated substrate (a7fd1e5d59b12)
in: master
6 files changed
tests/package.jsondiffbeforeafterboth--- a/tests/package.json
+++ b/tests/package.json
@@ -35,7 +35,7 @@
"testBurnItem": "mocha --timeout 9999999 -r ts-node/register ./**/burnItem.test.ts"
},
"author": "",
- "license": "Apache 2.0",
+ "license": "SEE LICENSE IN ../LICENSE",
"homepage": "",
"dependencies": {
"@polkadot/api": "^3.6.3",
tests/src/addToContractWhiteList.test.tsdiffbeforeafterboth--- a/tests/src/addToContractWhiteList.test.ts
+++ b/tests/src/addToContractWhiteList.test.ts
@@ -3,8 +3,7 @@
import usingApi, { submitTransactionAsync, submitTransactionExpectFailAsync } from "./substrate/substrate-api";
import privateKey from "./substrate/privateKey";
import {
- deployFlipper,
- getFlipValue
+ deployFlipper
} from "./util/contracthelpers";
import {
getGenericResult
@@ -12,9 +11,6 @@
chai.use(chaiAsPromised);
const expect = chai.expect;
-
-const value = 0;
-const gasLimit = 3000n * 1000000n;
describe('Integration Test addToContractWhiteList', () => {
tests/src/flipper/flipper.wasmdiffbeforeafterbothbinary blob — no preview
tests/src/flipper/metadata.jsondiffbeforeafterboth--- a/tests/src/flipper/metadata.json
+++ b/tests/src/flipper/metadata.json
@@ -1,15 +1,15 @@
{
"metadataVersion": "0.1.0",
"source": {
- "hash": "0x36431d9da78a6bb099474e49c9e35a9c3a04272b58815634082626109826cac6",
- "language": "ink! 3.0.0-rc1",
- "compiler": "rustc 1.49.0-nightly"
+ "hash": "0x5b02ceadaacee8408d3c6496394847092c099bcb897221dbe8d22c16d372fa17",
+ "language": "ink! 3.0.0-rc2",
+ "compiler": "rustc 1.51.0-nightly"
},
"contract": {
"name": "flipper",
- "version": "3.0.0-rc1",
+ "version": "0.1.0",
"authors": [
- "Parity Technologies <admin@parity.io>"
+ "[your_name] <[your_email]>"
]
},
"spec": {
@@ -27,7 +27,7 @@
}
],
"docs": [
- " Creates a new flipper smart contract initialized with the given value."
+ " Constructor that initializes the `bool` value to the given `init_value`."
],
"name": [
"new"
@@ -37,7 +37,9 @@
{
"args": [],
"docs": [
- " Creates a new flipper smart contract initialized to `false`."
+ " Constructor that initializes the `bool` value to `false`.",
+ "",
+ " Constructors can delegate to other constructors."
],
"name": [
"default"
@@ -51,7 +53,9 @@
{
"args": [],
"docs": [
- " Flips the current value of the Flipper's bool."
+ " A message that can be called on instantiated contracts.",
+ " This one flips the value of the stored `bool` from `true`",
+ " to `false` and vice versa."
],
"mutates": true,
"name": [
@@ -64,7 +68,7 @@
{
"args": [],
"docs": [
- " Returns the current value of the Flipper's bool."
+ " Simply returns the current value of our `bool`."
],
"mutates": false,
"name": [
tests/src/substrate/substrate-api.tsdiffbeforeafterboth--- a/tests/src/substrate/substrate-api.ts
+++ b/tests/src/substrate/substrate-api.ts
@@ -21,6 +21,15 @@
settings = settings || defaultApiOptions();
let api: ApiPromise = new ApiPromise(settings);
+ // TODO: Remove, this is temporary: Filter unneeded API output
+ // (Jaco promised it will be removed in the next version)
+ const consoleLog = console.log;
+ console.log = (message: string) => {
+ if (!(message.includes("API/INIT: Capabilities detected") || message.includes("2021-"))) {
+ consoleLog(message);
+ }
+ };
+
try {
await promisifySubstrate(api, async () => {
if(api) {
@@ -30,6 +39,7 @@
})();
} finally {
await api.disconnect();
+ console.log = consoleLog;
}
}
tests/src/util/contracthelpers.tsdiffbeforeafterboth1//2// This file is subject to the terms and conditions defined in3// file 'LICENSE', which is part of this source code package.4//56import chai from "chai";7import chaiAsPromised from 'chai-as-promised';8import { submitTransactionAsync } from "../substrate/substrate-api";9import fs from "fs";10import { Abi, BlueprintPromise as Blueprint, CodePromise, ContractPromise as Contract } from "@polkadot/api-contract";11import { IKeyringPair } from "@polkadot/types/types";12import { ApiPromise, Keyring } from "@polkadot/api";1314chai.use(chaiAsPromised);15const expect = chai.expect;16import { BigNumber } from 'bignumber.js';17import { findUnusedAddress } from '../util/helpers';1819const value = 0;20const gasLimit = 3000n * 1000000n;21const endowment = `1000000000000000`;2223function deployBlueprint(alice: IKeyringPair, code: CodePromise): Promise<Blueprint> {24 return new Promise<Blueprint>(async (resolve, reject) => {25 const unsub = await code26 .createBlueprint()27 .signAndSend(alice, (result) => {28 if (result.status.isInBlock || result.status.isFinalized) {29 // here we have an additional field in the result, containing the blueprint30 resolve(result.blueprint);31 unsub();32 }33 })34 });35}3637function deployContract(alice: IKeyringPair, blueprint: Blueprint) : Promise<any> {38 return new Promise<any>(async (resolve, reject) => {39 const endowment = 1000000000000000n;40 const initValue = true;4142 const unsub = await blueprint.tx43 .new(endowment, gasLimit, initValue)44 .signAndSend(alice, (result) => {45 if (result.status.isInBlock || result.status.isFinalized) {46 unsub();47 resolve(result);48 }49 }); 50 });51}5253async function prepareDeployer(api: ApiPromise) {54 // Find unused address55 const deployer = await findUnusedAddress(api);5657 // Transfer balance to it58 const keyring = new Keyring({ type: 'sr25519' });59 const alice = keyring.addFromUri(`//Alice`);60 let amount = new BigNumber(endowment);61 amount = amount.plus(1e15);62 const tx = api.tx.balances.transfer(deployer.address, amount.toFixed());63 await submitTransactionAsync(alice, tx);6465 return deployer;66}6768export async function deployFlipper(api: ApiPromise): Promise<[Contract, IKeyringPair]> {69 const metadata = JSON.parse(fs.readFileSync('./src/flipper/metadata.json').toString('utf-8'));70 const abi = new Abi(metadata);7172 const deployer = await prepareDeployer(api);7374 const wasm = fs.readFileSync('./src/flipper/flipper.wasm');7576 const code = new CodePromise(api, abi, wasm);7778 const blueprint = await deployBlueprint(deployer, code);79 const contract = (await deployContract(deployer, blueprint))['contract'] as Contract;8081 const initialGetResponse = await getFlipValue(contract, deployer);82 expect(initialGetResponse).to.be.true;8384 return [contract, deployer];85}8687export async function getFlipValue(contract: Contract, deployer: IKeyringPair) {88 const result = await contract.query.get(deployer.address, value, gasLimit);89 console.log(result);9091// if(!result.result.isSuccess) {92// throw `Failed to get flipper value`;93// }94// return (result.result.asSuccess.data[0] == 0x00) ? false : true;95 return false;96}