git.delta.rocks / unique-network / refs/commits / af54ef4128ee

difftreelog

Update tests to pass on updated substrate (a7fd1e5d59b12)

Greg Zaitsev2021-01-26parent: #13bdc4a.patch.diff
in: master

6 files changed

modifiedtests/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",
modifiedtests/src/addToContractWhiteList.test.tsdiffbeforeafterboth
before · tests/src/addToContractWhiteList.test.ts
1import chai from "chai";2import chaiAsPromised from 'chai-as-promised';3import usingApi, { submitTransactionAsync, submitTransactionExpectFailAsync } from "./substrate/substrate-api";4import privateKey from "./substrate/privateKey";5import {6  deployFlipper,7  getFlipValue8} from "./util/contracthelpers";9import {10  getGenericResult11} from "./util/helpers"1213chai.use(chaiAsPromised);14const expect = chai.expect;1516const value = 0;17const gasLimit = 3000n * 1000000n;1819describe('Integration Test addToContractWhiteList', () => {2021  it(`Add an address to a contract white list`, async () => {22    await usingApi(async api => {23      const bob = privateKey("//Bob");24      const [contract, deployer] = await deployFlipper(api);2526      const whiteListedBefore = (await api.query.nft.contractWhiteList(contract.address, bob.address)).toJSON();27      const addTx = api.tx.nft.addToContractWhiteList(contract.address, bob.address);28      const addEvents = await submitTransactionAsync(deployer, addTx);29      const whiteListedAfter = (await api.query.nft.contractWhiteList(contract.address, bob.address)).toJSON();3031      expect(getGenericResult(addEvents).success).to.be.true;32      expect(whiteListedBefore).to.be.false;33      expect(whiteListedAfter).to.be.true;34    });35  });3637  it(`Adding same address to white list repeatedly should not produce errors`, async () => {38    await usingApi(async api => {39      const bob = privateKey("//Bob");40      const [contract, deployer] = await deployFlipper(api);4142      const whiteListedBefore = (await api.query.nft.contractWhiteList(contract.address, bob.address)).toJSON();43      const addTx = api.tx.nft.addToContractWhiteList(contract.address, bob.address);44      const addEvents = await submitTransactionAsync(deployer, addTx);45      const whiteListedAfter = (await api.query.nft.contractWhiteList(contract.address, bob.address)).toJSON();46      const addAgainEvents = await submitTransactionAsync(deployer, addTx);47      const whiteListedAgainAfter = (await api.query.nft.contractWhiteList(contract.address, bob.address)).toJSON();4849      expect(getGenericResult(addEvents).success).to.be.true;50      expect(whiteListedBefore).to.be.false;51      expect(whiteListedAfter).to.be.true;52      expect(getGenericResult(addAgainEvents).success).to.be.true;53      expect(whiteListedAgainAfter).to.be.true;54    });55  });56});5758describe('Negative Integration Test addToContractWhiteList', () => {5960  it(`Add an address to a white list of a non-contract`, async () => {61    await usingApi(async api => {62      const alice = privateKey("//Bob");63      const bob = privateKey("//Bob");64      const charlieGuineaPig = privateKey("//Charlie");6566      const whiteListedBefore = (await api.query.nft.contractWhiteList(charlieGuineaPig.address, bob.address)).toJSON();67      const addTx = api.tx.nft.addToContractWhiteList(charlieGuineaPig.address, bob.address);68      await expect(submitTransactionExpectFailAsync(alice, addTx)).to.be.rejected;69      const whiteListedAfter = (await api.query.nft.contractWhiteList(charlieGuineaPig.address, bob.address)).toJSON();7071      expect(whiteListedBefore).to.be.false;72      expect(whiteListedAfter).to.be.false;73    });74  });7576  it(`Add to a contract white list using a non-owner address`, async () => {77    await usingApi(async api => {78      const bob = privateKey("//Bob");79      const [contract, deployer] = await deployFlipper(api);8081      const whiteListedBefore = (await api.query.nft.contractWhiteList(contract.address, bob.address)).toJSON();82      const addTx = api.tx.nft.addToContractWhiteList(contract.address, bob.address);83      await expect(submitTransactionExpectFailAsync(bob, addTx)).to.be.rejected;84      const whiteListedAfter = (await api.query.nft.contractWhiteList(contract.address, bob.address)).toJSON();8586      expect(whiteListedBefore).to.be.false;87      expect(whiteListedAfter).to.be.false;88    });89  });9091});
after · tests/src/addToContractWhiteList.test.ts
1import chai from "chai";2import chaiAsPromised from 'chai-as-promised';3import usingApi, { submitTransactionAsync, submitTransactionExpectFailAsync } from "./substrate/substrate-api";4import privateKey from "./substrate/privateKey";5import {6  deployFlipper7} from "./util/contracthelpers";8import {9  getGenericResult10} from "./util/helpers"1112chai.use(chaiAsPromised);13const expect = chai.expect;1415describe('Integration Test addToContractWhiteList', () => {1617  it(`Add an address to a contract white list`, async () => {18    await usingApi(async api => {19      const bob = privateKey("//Bob");20      const [contract, deployer] = await deployFlipper(api);2122      const whiteListedBefore = (await api.query.nft.contractWhiteList(contract.address, bob.address)).toJSON();23      const addTx = api.tx.nft.addToContractWhiteList(contract.address, bob.address);24      const addEvents = await submitTransactionAsync(deployer, addTx);25      const whiteListedAfter = (await api.query.nft.contractWhiteList(contract.address, bob.address)).toJSON();2627      expect(getGenericResult(addEvents).success).to.be.true;28      expect(whiteListedBefore).to.be.false;29      expect(whiteListedAfter).to.be.true;30    });31  });3233  it(`Adding same address to white list repeatedly should not produce errors`, async () => {34    await usingApi(async api => {35      const bob = privateKey("//Bob");36      const [contract, deployer] = await deployFlipper(api);3738      const whiteListedBefore = (await api.query.nft.contractWhiteList(contract.address, bob.address)).toJSON();39      const addTx = api.tx.nft.addToContractWhiteList(contract.address, bob.address);40      const addEvents = await submitTransactionAsync(deployer, addTx);41      const whiteListedAfter = (await api.query.nft.contractWhiteList(contract.address, bob.address)).toJSON();42      const addAgainEvents = await submitTransactionAsync(deployer, addTx);43      const whiteListedAgainAfter = (await api.query.nft.contractWhiteList(contract.address, bob.address)).toJSON();4445      expect(getGenericResult(addEvents).success).to.be.true;46      expect(whiteListedBefore).to.be.false;47      expect(whiteListedAfter).to.be.true;48      expect(getGenericResult(addAgainEvents).success).to.be.true;49      expect(whiteListedAgainAfter).to.be.true;50    });51  });52});5354describe('Negative Integration Test addToContractWhiteList', () => {5556  it(`Add an address to a white list of a non-contract`, async () => {57    await usingApi(async api => {58      const alice = privateKey("//Bob");59      const bob = privateKey("//Bob");60      const charlieGuineaPig = privateKey("//Charlie");6162      const whiteListedBefore = (await api.query.nft.contractWhiteList(charlieGuineaPig.address, bob.address)).toJSON();63      const addTx = api.tx.nft.addToContractWhiteList(charlieGuineaPig.address, bob.address);64      await expect(submitTransactionExpectFailAsync(alice, addTx)).to.be.rejected;65      const whiteListedAfter = (await api.query.nft.contractWhiteList(charlieGuineaPig.address, bob.address)).toJSON();6667      expect(whiteListedBefore).to.be.false;68      expect(whiteListedAfter).to.be.false;69    });70  });7172  it(`Add to a contract white list using a non-owner address`, async () => {73    await usingApi(async api => {74      const bob = privateKey("//Bob");75      const [contract, deployer] = await deployFlipper(api);7677      const whiteListedBefore = (await api.query.nft.contractWhiteList(contract.address, bob.address)).toJSON();78      const addTx = api.tx.nft.addToContractWhiteList(contract.address, bob.address);79      await expect(submitTransactionExpectFailAsync(bob, addTx)).to.be.rejected;80      const whiteListedAfter = (await api.query.nft.contractWhiteList(contract.address, bob.address)).toJSON();8182      expect(whiteListedBefore).to.be.false;83      expect(whiteListedAfter).to.be.false;84    });85  });8687});
modifiedtests/src/flipper/flipper.wasmdiffbeforeafterboth

binary blob — no preview

modifiedtests/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": [
modifiedtests/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;
   }
 }
 
modifiedtests/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;
 }