This repository was archived by the owner on Dec 27, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 43
Expand file tree
/
Copy pathwithdraw.spec.ts
More file actions
69 lines (63 loc) · 2.35 KB
/
withdraw.spec.ts
File metadata and controls
69 lines (63 loc) · 2.35 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
import { signChannelMessage, expect } from "@connext/vector-utils";
import { BigNumber } from "@ethersproject/bignumber";
import { AddressZero } from "@ethersproject/constants";
import { parseEther } from "@ethersproject/units";
import { deployments } from "hardhat";
import { ChannelMastercopy, ERC20 } from "../../typechain";
import { alice, bob, provider } from "../constants";
import { getContract, createChannel } from "../utils";
import { WithdrawCommitment } from "./withdraw";
describe("withdrawCommitment", function () {
this.timeout(120_000);
let channel: ChannelMastercopy;
let token: ERC20;
const amount = "50";
beforeEach(async () => {
await deployments.fixture(); // Start w fresh deployments
token = await getContract("TestToken", alice);
channel = await createChannel();
await (
await alice.sendTransaction({
to: channel.address,
value: BigNumber.from(amount).mul(2),
})
).wait();
await (await token.transfer(channel.address, parseEther(amount))).wait();
});
it("can successfully withdraw Eth", async () => {
const commitment = new WithdrawCommitment(
channel.address,
alice.address,
bob.address,
alice.address,
AddressZero,
amount,
"1",
);
await commitment.addSignatures(
await signChannelMessage(commitment.hashToSign(), alice.privateKey),
await signChannelMessage(commitment.hashToSign(), bob.privateKey),
);
expect((await provider.getBalance(channel.address)).eq(BigNumber.from(amount).mul(2)));
await alice.sendTransaction(await commitment.getSignedTransaction());
expect((await provider.getBalance(channel.address)).eq(BigNumber.from(amount)));
});
it("can successfully withdraw Tokens", async () => {
const commitment = new WithdrawCommitment(
channel.address,
alice.address,
bob.address,
alice.address,
token.address,
amount,
"1",
);
await commitment.addSignatures(
await signChannelMessage(commitment.hashToSign(), alice.privateKey),
await signChannelMessage(commitment.hashToSign(), bob.privateKey),
);
expect((await token.balanceOf(channel.address)).eq(BigNumber.from(amount).mul(2)));
await alice.sendTransaction(commitment.getSignedTransaction());
expect((await token.balanceOf(channel.address)).eq(BigNumber.from(amount)));
});
});