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.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 { WsProvider, ApiPromise } from "@polkadot/api";7import type { AccountId, Address, ApplyExtrinsicResult, DispatchError, DispatchInfo, EventRecord, Extrinsic, ExtrinsicStatus, Hash, RuntimeDispatchInfo } from '@polkadot/types/interfaces';8import { IKeyringPair } from "@polkadot/types/types";910import config from "../config";11import promisifySubstrate from "./promisify-substrate";12import { ApiOptions, SubmittableExtrinsic, ApiTypes } from "@polkadot/api/types";13import rtt from "../../../runtime_types.json";1415function defaultApiOptions(): ApiOptions {16 const wsProvider = new WsProvider(config.substrateUrl);17 return { provider: wsProvider, types: rtt };18}1920export default async function usingApi(action: (api: ApiPromise) => Promise<void>, settings: ApiOptions | undefined = undefined): Promise<void> {21 settings = settings || defaultApiOptions();22 let api: ApiPromise = new ApiPromise(settings);2324 try {25 await promisifySubstrate(api, async () => {26 if(api) {27 await api.isReadyOrError;28 await action(api);29 }30 })();31 } finally {32 await api.disconnect();33 }34}3536enum TransactionStatus {37 Success,38 Fail,39 NotReady40}4142function getTransactionStatus(events: EventRecord[], status: ExtrinsicStatus): TransactionStatus {43 if (status.isReady) {44 return TransactionStatus.NotReady;45 }46 if (status.isBroadcast) {47 return TransactionStatus.NotReady;48 } 49 if (status.isInBlock || status.isFinalized) {50 if(events.filter(e => e.event.data.method === 'ExtrinsicFailed').length > 0) {51 return TransactionStatus.Fail;52 }53 if(events.filter(e => e.event.data.method === 'ExtrinsicSuccess').length > 0) {54 return TransactionStatus.Success;55 }56 }5758 return TransactionStatus.Fail;59}6061export function62submitTransactionAsync(sender: IKeyringPair, transaction: SubmittableExtrinsic<ApiTypes>): Promise<EventRecord[]> {63 return new Promise(async (resolve, reject) => {64 try {65 await transaction.signAndSend(sender, ({ events = [], status }) => {66 const transactionStatus = getTransactionStatus(events, status);6768 if (transactionStatus === TransactionStatus.Success) {69 resolve(events);70 } else if (transactionStatus === TransactionStatus.Fail) {71 console.log(`Something went wrong with transaction. Status: ${status}`);72 reject(events);73 }74 });75 } catch (e) {76 console.log('Error: ', e);77 reject(e);78 }79 });80}8182export function submitTransactionExpectFailAsync(sender: IKeyringPair, transaction: SubmittableExtrinsic<ApiTypes>): Promise<EventRecord[]> {83 const consoleError = console.error;84 const consoleLog = console.log;85 console.error = () => {};86 console.log = () => {};8788 return new Promise<EventRecord[]>(async function(res, rej) {89 const resolve = (rec: EventRecord[]) => {90 setTimeout(() => {91 res(rec);92 console.error = consoleError;93 console.log = consoleLog;94 });95 };96 const reject = (errror: any) => {97 setTimeout(() => {98 rej(errror);99 console.error = consoleError;100 console.log = consoleLog;101 });102 };103 try {104 await transaction.signAndSend(sender, ({ events = [], status }) => {105 const transactionStatus = getTransactionStatus(events, status);106107 console.log('transactionStatus', transactionStatus, 'events', events);108109 if (transactionStatus == TransactionStatus.Success) {110 resolve(events);111 } else if (transactionStatus == TransactionStatus.Fail) {112 reject(events);113 }114 });115 } catch (e) {116 reject(e);117 }118 });119}1//2// This file is subject to the terms and conditions defined in3// file 'LICENSE', which is part of this source code package.4//56import { WsProvider, ApiPromise } from "@polkadot/api";7import type { AccountId, Address, ApplyExtrinsicResult, DispatchError, DispatchInfo, EventRecord, Extrinsic, ExtrinsicStatus, Hash, RuntimeDispatchInfo } from '@polkadot/types/interfaces';8import { IKeyringPair } from "@polkadot/types/types";910import config from "../config";11import promisifySubstrate from "./promisify-substrate";12import { ApiOptions, SubmittableExtrinsic, ApiTypes } from "@polkadot/api/types";13import rtt from "../../../runtime_types.json";1415function defaultApiOptions(): ApiOptions {16 const wsProvider = new WsProvider(config.substrateUrl);17 return { provider: wsProvider, types: rtt };18}1920export default async function usingApi(action: (api: ApiPromise) => Promise<void>, settings: ApiOptions | undefined = undefined): Promise<void> {21 settings = settings || defaultApiOptions();22 let api: ApiPromise = new ApiPromise(settings);2324 // TODO: Remove, this is temporary: Filter unneeded API output 25 // (Jaco promised it will be removed in the next version)26 const consoleLog = console.log;27 console.log = (message: string) => {28 if (!(message.includes("API/INIT: Capabilities detected") || message.includes("2021-"))) {29 consoleLog(message);30 }31 };3233 try {34 await promisifySubstrate(api, async () => {35 if(api) {36 await api.isReadyOrError;37 await action(api);38 }39 })();40 } finally {41 await api.disconnect();42 console.log = consoleLog;43 }44}4546enum TransactionStatus {47 Success,48 Fail,49 NotReady50}5152function getTransactionStatus(events: EventRecord[], status: ExtrinsicStatus): TransactionStatus {53 if (status.isReady) {54 return TransactionStatus.NotReady;55 }56 if (status.isBroadcast) {57 return TransactionStatus.NotReady;58 } 59 if (status.isInBlock || status.isFinalized) {60 if(events.filter(e => e.event.data.method === 'ExtrinsicFailed').length > 0) {61 return TransactionStatus.Fail;62 }63 if(events.filter(e => e.event.data.method === 'ExtrinsicSuccess').length > 0) {64 return TransactionStatus.Success;65 }66 }6768 return TransactionStatus.Fail;69}7071export function72submitTransactionAsync(sender: IKeyringPair, transaction: SubmittableExtrinsic<ApiTypes>): Promise<EventRecord[]> {73 return new Promise(async (resolve, reject) => {74 try {75 await transaction.signAndSend(sender, ({ events = [], status }) => {76 const transactionStatus = getTransactionStatus(events, status);7778 if (transactionStatus === TransactionStatus.Success) {79 resolve(events);80 } else if (transactionStatus === TransactionStatus.Fail) {81 console.log(`Something went wrong with transaction. Status: ${status}`);82 reject(events);83 }84 });85 } catch (e) {86 console.log('Error: ', e);87 reject(e);88 }89 });90}9192export function submitTransactionExpectFailAsync(sender: IKeyringPair, transaction: SubmittableExtrinsic<ApiTypes>): Promise<EventRecord[]> {93 const consoleError = console.error;94 const consoleLog = console.log;95 console.error = () => {};96 console.log = () => {};9798 return new Promise<EventRecord[]>(async function(res, rej) {99 const resolve = (rec: EventRecord[]) => {100 setTimeout(() => {101 res(rec);102 console.error = consoleError;103 console.log = consoleLog;104 });105 };106 const reject = (errror: any) => {107 setTimeout(() => {108 rej(errror);109 console.error = consoleError;110 console.log = consoleLog;111 });112 };113 try {114 await transaction.signAndSend(sender, ({ events = [], status }) => {115 const transactionStatus = getTransactionStatus(events, status);116117 console.log('transactionStatus', transactionStatus, 'events', events);118119 if (transactionStatus == TransactionStatus.Success) {120 resolve(events);121 } else if (transactionStatus == TransactionStatus.Fail) {122 reject(events);123 }124 });125 } catch (e) {126 reject(e);127 }128 });129}tests/src/util/contracthelpers.tsdiffbeforeafterboth--- a/tests/src/util/contracthelpers.ts
+++ b/tests/src/util/contracthelpers.ts
@@ -86,11 +86,9 @@
export async function getFlipValue(contract: Contract, deployer: IKeyringPair) {
const result = await contract.query.get(deployer.address, value, gasLimit);
- console.log(result);
-// if(!result.result.isSuccess) {
-// throw `Failed to get flipper value`;
-// }
-// return (result.result.asSuccess.data[0] == 0x00) ? false : true;
- return false;
+ if(!result.result.isOk) {
+ throw `Failed to get flipper value`;
+ }
+ return (result.result.asOk.data[0] == 0x00) ? false : true;
}