Skip to content

Commit

Permalink
sdk: fix tests and add changelog for new gasPriceFactor behavior
Browse files Browse the repository at this point in the history
  • Loading branch information
andrevmatos committed Sep 21, 2021
1 parent f8d4132 commit 7b068d5
Show file tree
Hide file tree
Showing 5 changed files with 87 additions and 31 deletions.
3 changes: 3 additions & 0 deletions raiden-ts/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,11 @@
## [Unreleased]
### Changed
- [#2949] Allows `Raiden.transfer`'s `options.paths` to receive a broader schema, including `{ route: Address[]; estimated_fee: Int<32>; address_metadata?: ... }[]`, needed to support CLI's `paths` parameter of `/payments` endpoint
- [#2953] `config.gasPriceFactor` applies over `maxPriorityFeePerGas`, using the new fee parameters from London when possible; now, by default, no fee parameters are specified, leaving `ethers` and provider (e.g. Metamask) to figure out best gas fees, fixing [#2952];

[#2949]: https://github.com/raiden-network/light-client/issues/2949
[#2952]: https://github.com/raiden-network/light-client/issues/2952
[#2953]: https://github.com/raiden-network/light-client/pull/2953

## [2.0.0-rc.2] - 2021-09-14

Expand Down
106 changes: 77 additions & 29 deletions raiden-ts/tests/integration/channels.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ import { first, pluck } from 'rxjs/operators';
import { raidenConfigUpdate } from '@/actions';
import { ChannelState } from '@/channels';
import {
blockGasprice,
channelClose,
channelDeposit,
channelMonitored,
Expand Down Expand Up @@ -543,15 +544,11 @@ describe('channelDepositEpic', () => {
channelDeposit.failure(expect.any(Error), { tokenNetwork, partner: partner.address }),
);
expect(tokenContract.approve).toHaveBeenCalledTimes(2);
expect(tokenContract.approve).toHaveBeenCalledWith(
tokenNetwork,
0,
expect.objectContaining({ gasPrice: expect.toBeBigNumber() }),
);
expect(tokenContract.approve).toHaveBeenCalledWith(tokenNetwork, 0, expect.anything());
expect(tokenContract.approve).toHaveBeenCalledWith(
tokenNetwork,
raiden.config.minimumAllowance,
expect.objectContaining({ gasPrice: expect.toBeBigNumber() }),
expect.anything(),
);
});

Expand Down Expand Up @@ -621,7 +618,7 @@ describe('channelDepositEpic', () => {
raiden.address,
deposit.add(prevDeposit),
partner.address,
expect.objectContaining({ gasPrice: expect.toBeBigNumber() }),
expect.anything(),
);
expect(setTotalDepositTx.wait).toHaveBeenCalledTimes(1);
});
Expand Down Expand Up @@ -661,7 +658,7 @@ describe('channelDepositEpic', () => {
raiden.address,
deposit,
partner.address,
expect.objectContaining({ gasPrice: expect.toBeBigNumber() }),
expect.anything(),
);
});
});
Expand Down Expand Up @@ -747,7 +744,7 @@ describe('channelCloseEpic', () => {
expect.any(String), // additional_hash
expect.any(String), // non_closing_signature
expect.any(String), // closing_signature
expect.objectContaining({ gasPrice: expect.toBeBigNumber() }),
expect.anything(),
);
expect(closeTx.wait).toHaveBeenCalledTimes(1);
});
Expand Down Expand Up @@ -860,7 +857,7 @@ describe('channelSettleEpic', () => {
Zero, // partner transfered amount
Zero, // partner locked amount
LocksrootZero, // partner locksroot
expect.objectContaining({ gasPrice: expect.toBeBigNumber() }),
expect.anything(),
);
expect(settleTx.wait).toHaveBeenCalledTimes(1);
});
Expand Down Expand Up @@ -935,7 +932,7 @@ describe('channelSettleEpic', () => {
Zero, // self transfered amount
amount, // self locked amount
getLocksroot([locked.lock]), // self locksroot
expect.objectContaining({ gasPrice: expect.toBeBigNumber() }),
expect.anything(),
);
expect(settleTx.wait).toHaveBeenCalledTimes(1);
expect(tokenNetworkContract.getChannelParticipantInfo).toHaveBeenCalledTimes(2);
Expand Down Expand Up @@ -1011,7 +1008,7 @@ describe('channelSettleEpic', () => {
Zero, // partner transfered amount
amount, // partner locked amount
getLocksroot([locked.lock]), // partner locksroot
expect.objectContaining({ gasPrice: expect.toBeBigNumber() }),
expect.anything(),
);
expect(settleTx.wait).toHaveBeenCalledTimes(1);
expect(tokenNetworkContract.getChannelParticipantInfo).toHaveBeenCalledTimes(2);
Expand Down Expand Up @@ -1050,7 +1047,7 @@ describe('channelUnlockEpic', () => {
raiden.address,
partner.address,
expect.any(Uint8Array),
expect.objectContaining({ gasPrice: expect.toBeBigNumber() }),
expect.anything(),
);
});

Expand Down Expand Up @@ -1081,7 +1078,7 @@ describe('channelUnlockEpic', () => {
raiden.address,
partner.address,
expect.any(Uint8Array),
expect.objectContaining({ gasPrice: expect.toBeBigNumber() }),
expect.anything(),
);
});
});
Expand Down Expand Up @@ -1151,21 +1148,72 @@ test('stale provider disables receiving', async () => {
expect(raiden.config.caps?.[Capabilities.RECEIVE]).toBeTruthy();
});

test('blockGasPriceEpic updates latest.gasPrice on new block', async () => {
expect.assertions(3);
describe('blockGasPriceEpic', () => {
test('updates latest.gasPrice on new block', async () => {
expect.assertions(7);

const raiden = await makeRaiden(undefined, false);
raiden.deps.provider.getGasPrice.mockResolvedValue(BigNumber.from(2e9));
await raiden.start();
await sleep();
await expect(firstValueFrom(raiden.deps.latest$.pipe(pluck('gasPrice')))).resolves.toEqual(
BigNumber.from(2e9),
);
const raiden = await makeRaiden(undefined, false);
raiden.deps.provider.getFeeData.mockResolvedValue({
maxFeePerGas: BigNumber.from(1e9),
maxPriorityFeePerGas: BigNumber.from(2.5e9),
gasPrice: null,
});

raiden.deps.provider.getGasPrice.mockResolvedValue(BigNumber.from(3e9));
await waitBlock();
await expect(firstValueFrom(raiden.deps.latest$.pipe(pluck('gasPrice')))).resolves.toEqual(
BigNumber.from(3e9),
);
expect(raiden.deps.provider.getGasPrice).toHaveBeenCalledTimes(2);
await raiden.start();
await sleep();
await expect(
firstValueFrom(raiden.deps.latest$.pipe(pluck('gasPrice'))),
).resolves.toBeUndefined();

raiden.store.dispatch(raidenConfigUpdate({ gasPriceFactor: 2.0 }));
await waitBlock();
expect(raiden.output.filter(blockGasprice.is)).toHaveLength(2);
await expect(firstValueFrom(raiden.deps.latest$.pipe(pluck('gasPrice')))).resolves.toEqual({
// maxFeePerGas must contain increased maxPriorityFeePerGas
maxFeePerGas: expect.toBeBigNumber(1e9 + 2.5e9),
maxPriorityFeePerGas: expect.toBeBigNumber(2.5e9 * 2),
});

raiden.deps.provider.getFeeData.mockResolvedValue({
maxFeePerGas: BigNumber.from(1.1e9), // increase maxFeePerGas
maxPriorityFeePerGas: BigNumber.from(2.5e9),
gasPrice: null,
});
await waitBlock();
expect(raiden.output.filter(blockGasprice.is)).toHaveLength(3);
await expect(firstValueFrom(raiden.deps.latest$.pipe(pluck('gasPrice')))).resolves.toEqual({
// maxFeePerGas must contain increased maxPriorityFeePerGas
maxFeePerGas: expect.toBeBigNumber(1.1e9 + 2.5e9),
maxPriorityFeePerGas: expect.toBeBigNumber(2.5e9 * 2),
});

expect(raiden.deps.provider.getGasPrice).not.toHaveBeenCalled();
expect(raiden.deps.provider.getFeeData).toHaveBeenCalledTimes(2);
});

test('supports legacy networks', async () => {
expect.assertions(3);

const raiden = await makeRaiden(undefined, false);
raiden.deps.provider.getFeeData.mockResolvedValue({
maxFeePerGas: null,
maxPriorityFeePerGas: null,
gasPrice: BigNumber.from(1e9),
});

await raiden.start();
await waitBlock();

await expect(
firstValueFrom(raiden.deps.latest$.pipe(pluck('gasPrice'))),
).resolves.toBeUndefined();

raiden.store.dispatch(raidenConfigUpdate({ gasPriceFactor: 2.0 }));
await waitBlock();
await waitBlock();
expect(raiden.output.filter(blockGasprice.is)).toHaveLength(2);
await expect(firstValueFrom(raiden.deps.latest$.pipe(pluck('gasPrice')))).resolves.toEqual({
gasPrice: expect.toBeBigNumber(2e9),
});
});
});
5 changes: 5 additions & 0 deletions raiden-ts/tests/integration/mocks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -697,6 +697,11 @@ export async function makeRaiden(
);
jest.spyOn(provider, 'getTransaction');
jest.spyOn(provider, 'getGasPrice').mockResolvedValue(BigNumber.from(1e9));
jest.spyOn(provider, 'getFeeData').mockResolvedValue({
maxFeePerGas: BigNumber.from(1e9),
maxPriorityFeePerGas: BigNumber.from(2.5e9),
gasPrice: null,
});
jest.spyOn(provider, 'listAccounts').mockResolvedValue([address]);
// See: https://github.com/cartant/rxjs-marbles/issues/11
jest.spyOn(provider, 'getBlockNumber').mockImplementation(async () => provider.blockNumber);
Expand Down
2 changes: 1 addition & 1 deletion raiden-ts/tests/integration/withdraw.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -333,7 +333,7 @@ describe('withdraw send request', () => {
expiration,
request.signature,
confirmation.signature,
expect.objectContaining({ gasPrice: expect.toBeBigNumber() }),
expect.anything(),
);
// this only works because Capabilities.DELIVERY is enabled
// LC-to-LC confirms with WithdrawConfirmation instead
Expand Down
2 changes: 1 addition & 1 deletion raiden-ts/tests/unit/raiden.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1449,7 +1449,7 @@ describe('Raiden', () => {
token,
MaxUint256,
MaxUint256,
expect.objectContaining({ gasPrice: expect.toBeBigNumber() }),
expect.anything(),
);
});

Expand Down

0 comments on commit 7b068d5

Please sign in to comment.