Skip to content

Commit b05e323

Browse files
committed
Simplified debt test
1 parent 8c69eb1 commit b05e323

File tree

2 files changed

+20
-7
lines changed

2 files changed

+20
-7
lines changed

contracts/Split3.sol

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ contract Split3 {
1717
require(sent, "Failed to send");
1818
}
1919

20-
// Track debt transactions
20+
// Track debt transactions between two partites
2121
function adjust(address debtor, address payer, int amount) public {
2222
balances[debtor] -= amount;
2323
balances[payer] += amount;

test/test.js

Lines changed: 19 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,6 @@ const zero = ethers.utils.parseEther("0");
55
const one = ethers.utils.parseEther("1.0");
66
const negOne = ethers.utils.parseEther("-1.0");
77

8-
// @deprecated
9-
async function address() {
10-
const signer = await ethers.getSigner();
11-
return await signer.getAddress();
12-
}
13-
148
async function deploy() {
159
const Split3 = await ethers.getContractFactory("Split3");
1610
const split3 = await Split3.deploy();
@@ -123,4 +117,23 @@ describe("Split3", () => {
123117
// expect(await ethers.provider.getBalance(aliceAddr)).to.equal(one.mul(10001)); // FIXME these assertions are flaky since gas prices affect the balance
124118
// expect(await ethers.provider.getBalance(bobAddr)).to.equal(one.mul(9999));
125119
});
120+
121+
it("Simplified debt", async () => {
122+
const contract = await deploy();
123+
const [aliceAddr, aliceContract] = await getOther(contract, 1);
124+
const [bobAddr, bobContract] = await getOther(contract, 2);
125+
const [charlieAddr, charlieContract] = await getOther(contract, 2);
126+
127+
await (await aliceContract.adjust(bobAddr, aliceAddr, one)).wait();
128+
await assertBalances(contract, 2);
129+
130+
await (await bobContract.adjust(charlieAddr, bobAddr, one)).wait();
131+
await assertBalances(contract, 2);
132+
133+
await (await charlieContract.settle(aliceAddr, { value: one })).wait();
134+
await assertBalances(contract, 2);
135+
expect(await contract.balances(aliceAddr)).to.equal(zero);
136+
expect(await contract.balances(bobAddr)).to.equal(zero);
137+
expect(await contract.balances(charlieAddr)).to.equal(zero);
138+
});
126139
});

0 commit comments

Comments
 (0)