Skip to content
This repository was archived by the owner on Mar 23, 2021. It is now read-only.

Commit d1fb80e

Browse files
Merge #1752 #1753
1752: Remove outdated talk about the internal folder r=mergify[bot] a=thomaseizinger 1753: Better wallet assertions r=mergify[bot] a=thomaseizinger This improves the assertions in two ways: 1. Before we check the wallet balances, we wait until cnd reports the swap as 'SWAPPED'. 2. We use `bn-chai` to compare the balances to improve the error message. In case of failure, we now get: ![image](https://user-images.githubusercontent.com/5486389/70546710-102ea180-1b70-11ea-9785-64546a011523.png) Fixes #1719. (Hopefully) Co-authored-by: Thomas Eizinger <thomas@eizinger.io>
3 parents 1e768bf + d6cc91e + d248905 commit d1fb80e

File tree

8 files changed

+36
-13
lines changed

8 files changed

+36
-13
lines changed

README.md

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,12 +18,9 @@ This is a reference implementation for the COMIT protocol.
1818

1919
This repository is a cargo workspace:
2020

21-
- Crates at the top level are where the main work happens. Consult the respective `Cargo.toml` for a description of what they do.
22-
- Crates inside the [internal](./internal) folder are considered to be private to this repository. They are used for sharing code between other crates in this repository.
23-
There is an [ongoing effort](https://github.com/comit-network/comit-rs/issues/626) to get rid of these crates because path dependencies block us from releasing any of the other crates to crates.io.
21+
- `cnd`: implementation of the comit-network daemon
2422
- `libp2p-comit`: implementation of the comit messaging protocol on top of libp2p
2523

26-
2724
## Setup build environment
2825

2926
All you need is ~love~ rust: `curl https://sh.rustup.rs -sSf | sh`

api_tests/lib/setup_chai.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,21 @@
11
// A helper file to configure chai with all the plugins we need
22
// This is to reduce noise in our actual test files
33

4+
import chaiBn = require("bn-chai");
45
import { tv4, use } from "chai";
56
import chaiAsPromised from "chai-as-promised";
67
import chaiEach = require("chai-each");
78
import chaiHttp = require("chai-http");
89
import chaiJsonSchema = require("chai-json-schema");
910
import chaiSubset = require("chai-subset");
11+
import { BigNumber } from "ethers/utils";
1012
import * as sirenJsonSchema from "../siren.schema.json";
1113

1214
use(chaiAsPromised);
1315
use(chaiHttp);
1416
use(chaiSubset);
1517
use(chaiEach);
1618
use(chaiJsonSchema);
19+
use(chaiBn(BigNumber));
1720

1821
tv4.addSchema("http://sirenspec.org/schema", sirenJsonSchema);

api_tests/lib_sdk/actors/actor.ts

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -204,6 +204,16 @@ export class Actor {
204204
}
205205

206206
public async assertSwapped() {
207+
this.logger.debug("Checking if cnd reports status 'SWAPPED'");
208+
209+
while (true) {
210+
await sleep(200);
211+
const entity = await this.swap.fetchDetails();
212+
if (entity.properties.status === "SWAPPED") {
213+
break;
214+
}
215+
}
216+
207217
for (const [
208218
assetKind,
209219
expectedBalanceChange,
@@ -222,15 +232,10 @@ export class Actor {
222232
).add(expectedBalanceChange);
223233
const maximumFee = wallet.MaximumFee;
224234

225-
await expect(
226-
wallet
227-
.getBalance()
228-
.then(balance =>
229-
new BigNumber(balance).gte(
230-
expectedBalance.sub(maximumFee)
231-
)
232-
)
233-
).to.eventually.be.true;
235+
const balanceInclFees = expectedBalance.sub(maximumFee);
236+
const currentWalletBalance = await wallet.getBalance();
237+
238+
expect(currentWalletBalance).to.be.gte.BN(balanceInclFees);
234239
}
235240
}
236241

api_tests/lib_sdk/cnd_config.ts

Whitespace-only changes.

api_tests/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@
3535
"bignumber.js": "^9.0.0",
3636
"bitcoin-core": "^3.0.0",
3737
"bitcoinjs-lib": "^5.1.6",
38+
"bn-chai": "^1.0.1",
3839
"chai": "^4.2.0",
3940
"chai-as-promised": "^7.1.1",
4041
"chai-each": "^0.0.1",

api_tests/tslint.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
"no-shadowed-variable": false,
1414
"object-literal-sort-keys": false,
1515
"no-reference": false,
16+
"no-namespace": false,
1617
"only-arrow-functions": false,
1718
"file-name-casing": [true, "snake-case"]
1819
},

api_tests/types/bn-chai/index.d.ts

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
declare module "bn-chai" {
2+
function bnChaiFn(ctor: any): Chai.ChaiPlugin;
3+
4+
export = bnChaiFn;
5+
}
6+
7+
declare namespace Chai {
8+
interface NumberComparer {
9+
BN(value: any): void;
10+
}
11+
}

api_tests/yarn.lock

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -590,6 +590,11 @@ bmutex@~0.1.6:
590590
dependencies:
591591
bsert "~0.0.10"
592592

593+
bn-chai@^1.0.1:
594+
version "1.0.1"
595+
resolved "https://registry.yarnpkg.com/bn-chai/-/bn-chai-1.0.1.tgz#5d6e9654162602a527b08a1546e60cfb44213725"
596+
integrity sha512-7rJXt21DwYiLLpvzLaACixBBoUGkRV1iuFD3wElEhw8Ji9IiY/QsJRtvW+c7ChRgEOyLQkGaSGFUUqBKm21SNA==
597+
593598
bn.js@^4.11.8, bn.js@^4.4.0:
594599
version "4.11.8"
595600
resolved "https://registry.yarnpkg.com/bn.js/-/bn.js-4.11.8.tgz#2cde09eb5ee341f484746bb0309b3253b1b1442f"

0 commit comments

Comments
 (0)