Skip to content

Commit

Permalink
sdk: add changelog & tests for UDC totalDeposit issue
Browse files Browse the repository at this point in the history
  • Loading branch information
andrevmatos committed Oct 20, 2020
1 parent 7ee3237 commit e49c217
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 9 deletions.
4 changes: 3 additions & 1 deletion raiden-ts/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,10 @@

## [Unreleased]
### Fixed
- [#2078] Check for overflows before sending transfers
- [#2094] Fix TransferState's timestamps missing
- [#2174] Fix a few transport issues triggered on high-load scenarios
- [#2078] Check for overflows before sending transfers
- [#2275] Fix mismatch between UDC totalDeposit and effectiveBalance

### Added
- [#2044] Introduce PouchDB (IndexedDB/leveldown) as new persistent state storage backend
Expand All @@ -21,6 +22,7 @@
[#2174]: https://github.com/raiden-network/light-client/pull/2174
[#2204]: https://github.com/raiden-network/light-client/issues/2204
[#2205]: https://github.com/raiden-network/light-client/issues/2205
[#2275]: https://github.com/raiden-network/light-client/issues/2225

## [0.11.1] - 2020-08-18
### Changed
Expand Down
17 changes: 13 additions & 4 deletions raiden-ts/tests/integration/raiden.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1299,14 +1299,17 @@ describe('Raiden', () => {
});

test('deposit success', async () => {
expect.assertions(1);
await raiden.mint(await raiden.userDepositTokenAddress(), 10);
expect.assertions(3);
await raiden.mint(await raiden.userDepositTokenAddress(), 20);
await expect(raiden.depositToUDC(10)).resolves.toMatch(/^0x[0-9a-fA-F]{64}$/);
await expect(raiden.depositToUDC(5)).resolves.toMatch(/^0x[0-9a-fA-F]{64}$/);
await expect(raiden.getUDCCapacity()).resolves.toEqual(bigNumberify(15));
});

test('withdraw success', async () => {
expect.assertions(5);
test('withdraw success!', async () => {
expect.assertions(7);
const deposit = bigNumberify(100) as UInt<32>;
const newDeposit = bigNumberify(30) as UInt<32>;
const withdraw = bigNumberify(80) as UInt<32>;
await raiden.mint(await raiden.userDepositTokenAddress(), deposit);
await expect(raiden.depositToUDC(deposit)).resolves.toMatch(/^0x[0-9a-fA-F]{64}$/);
Expand All @@ -1325,6 +1328,12 @@ describe('Raiden', () => {
amount: withdraw,
}),
]);

await expect(raiden.depositToUDC(newDeposit)).resolves.toMatch(/^0x[0-9a-fA-F]{64}$/);
await provider.mine(confirmationBlocks * 2);
await expect(raiden.getUDCCapacity()).resolves.toEqual(
deposit.sub(withdraw).add(newDeposit),
);
});

test('withdraw success with restart', async () => {
Expand Down
17 changes: 13 additions & 4 deletions raiden-ts/tests/unit/epics/monitor.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,21 +45,23 @@ test('monitorUdcBalanceEpic', async () => {
const raiden = await makeRaiden(undefined, false);
const { userDepositContract } = raiden.deps;
userDepositContract.functions.effectiveBalance.mockResolvedValue(Zero);
userDepositContract.functions.total_deposit.mockResolvedValue(Zero);

await raiden.start();
await sleep();
expect(raiden.output).toContainEqual(
udcDeposit.success(undefined, { totalDeposit: Zero as UInt<32> }),
udcDeposit.success({ balance: Zero as UInt<32> }, { totalDeposit: Zero as UInt<32> }),
);
await expect(
raiden.deps.latest$.pipe(pluck('udcBalance'), first()).toPromise(),
).resolves.toEqual(Zero);

const balance = bigNumberify(23) as UInt<32>;
userDepositContract.functions.effectiveBalance.mockResolvedValue(balance);
userDepositContract.functions.total_deposit.mockResolvedValue(balance);
await waitBlock();

expect(raiden.output).toContainEqual(udcDeposit.success(undefined, { totalDeposit: balance }));
expect(raiden.output).toContainEqual(udcDeposit.success({ balance }, { totalDeposit: balance }));
await expect(
raiden.deps.latest$.pipe(pluck('udcBalance'), first()).toPromise(),
).resolves.toEqual(balance);
Expand Down Expand Up @@ -182,10 +184,12 @@ describe('monitorRequestEpic', () => {
);

userDepositContract.functions.effectiveBalance.mockResolvedValue(monitoringReward.sub(1));
userDepositContract.functions.total_deposit.mockResolvedValue(monitoringReward.sub(1));
await waitBlock();

const balance = monitoringReward.sub(1) as UInt<32>;
expect(raiden.output).toContainEqual(
udcDeposit.success(undefined, { totalDeposit: monitoringReward.sub(1) as UInt<32> }),
udcDeposit.success({ balance }, { totalDeposit: balance }),
);

await ensureChannelIsDeposited([raiden, partner], deposit);
Expand Down Expand Up @@ -389,6 +393,7 @@ describe('udcDepositEpic', () => {
const raiden = await makeRaiden(undefined, false);
const { userDepositContract } = raiden.deps;
userDepositContract.functions.effectiveBalance.mockResolvedValue(Zero);
userDepositContract.functions.total_deposit.mockResolvedValue(Zero);

const tokenContract = raiden.deps.getTokenContract(
await raiden.deps.userDepositContract.functions.token(),
Expand All @@ -413,6 +418,7 @@ describe('udcDepositEpic', () => {
const raiden = await makeRaiden(undefined, false);
const { userDepositContract } = raiden.deps;
userDepositContract.functions.effectiveBalance.mockResolvedValue(Zero);
userDepositContract.functions.total_deposit.mockResolvedValue(Zero);

const tokenContract = raiden.deps.getTokenContract(
await raiden.deps.userDepositContract.functions.token(),
Expand Down Expand Up @@ -452,6 +458,7 @@ describe('udcDepositEpic', () => {
const raiden = await makeRaiden(undefined, false);
const { userDepositContract } = raiden.deps;
userDepositContract.functions.effectiveBalance.mockResolvedValue(Zero);
userDepositContract.functions.total_deposit.mockResolvedValue(Zero);

const tokenContract = raiden.deps.getTokenContract(
await raiden.deps.userDepositContract.functions.token(),
Expand Down Expand Up @@ -483,6 +490,7 @@ describe('udcDepositEpic', () => {
const raiden = await makeRaiden(undefined, false);
const { userDepositContract } = raiden.deps;
userDepositContract.functions.effectiveBalance.mockResolvedValue(prevDeposit);
userDepositContract.functions.total_deposit.mockResolvedValue(prevDeposit);

const tokenContract = raiden.deps.getTokenContract(
await raiden.deps.userDepositContract.functions.token(),
Expand All @@ -501,6 +509,7 @@ describe('udcDepositEpic', () => {

const depositTx = makeTransaction(undefined, { to: userDepositContract.address });
userDepositContract.functions.deposit.mockResolvedValue(depositTx);
userDepositContract.functions.effectiveBalance.mockResolvedValue(balance);

await raiden.start();
raiden.store.dispatch(udcDeposit.request({ deposit }, { totalDeposit: balance }));
Expand All @@ -515,7 +524,7 @@ describe('udcDepositEpic', () => {
);
expect(raiden.output).toContainEqual(
udcDeposit.success(
{ txHash: depositTx.hash! as Hash, txBlock: expect.any(Number), confirmed: true },
{ balance, txHash: depositTx.hash! as Hash, txBlock: expect.any(Number), confirmed: true },
{ totalDeposit: balance },
),
);
Expand Down

0 comments on commit e49c217

Please sign in to comment.