Skip to content

Commit

Permalink
fix: any-to-erc20 token validation (#517)
Browse files Browse the repository at this point in the history
  • Loading branch information
benjlevesque committed Jun 1, 2021
1 parent a91ae11 commit 9e3ab6d
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 8 deletions.
Expand Up @@ -176,7 +176,12 @@ export default class AnyToErc20ProxyPaymentNetwork extends Erc20FeeProxyPaymentN
);
}

if (!supportedCurrencies[network][request.currency.type].includes(request.currency.value)) {
const currency =
request.currency.type === RequestLogicTypes.CURRENCY.ERC20
? request.currency.value.toLowerCase()
: request.currency.value;

if (!supportedCurrencies[network][request.currency.type].includes(currency)) {
throw new Error(
`The currency (${request.currency.value}) of the request is not supported for this payment network.`,
);
Expand Down
Expand Up @@ -358,6 +358,25 @@ describe('extensions/payment-network/erc20/any-to-erc20-fee-proxy-contract', ()
).toEqual(DataConversionERC20FeeCreate.extensionFullState);
});

it('can applyActionToExtensions of creation when address is checksumed', () => {
const request = Utils.deepCopy(DataConversionERC20FeeCreate.requestStateNoExtensions);
request.currency = {
type: RequestLogicTypes.CURRENCY.ERC20,
value: '0x4E15361FD6b4BB609Fa63C81A2be19d873717870', // FTM
network: 'mainnet',
};

expect(
anyToErc20Proxy.applyActionToExtension(
request.extensions,
DataConversionERC20FeeCreate.actionCreationFull,
request,
TestData.otherIdRaw.identity,
TestData.arbitraryTimestamp,
),
).toEqual(DataConversionERC20FeeCreate.extensionFullState);
});

it('cannot applyActionToExtensions of creation with a previous state', () => {
// 'must throw'
expect(() => {
Expand Down Expand Up @@ -653,7 +672,7 @@ describe('extensions/payment-network/erc20/any-to-erc20-fee-proxy-contract', ()
),
).toEqual(DataConversionERC20FeeAddData.extensionStateWithFeeAfterCreation);
});

it('cannot applyActionToExtensions of addFee without a previous state', () => {
expect(() => {
anyToErc20Proxy.applyActionToExtension(
Expand All @@ -665,7 +684,7 @@ describe('extensions/payment-network/erc20/any-to-erc20-fee-proxy-contract', ()
);
}).toThrowError(`The extension should be created before receiving any other action`);
});

it('cannot applyActionToExtensions of addFee without a payee', () => {
const previousState = Utils.deepCopy(DataConversionERC20FeeCreate.requestStateCreatedEmpty);
previousState.payee = undefined;
Expand All @@ -679,7 +698,7 @@ describe('extensions/payment-network/erc20/any-to-erc20-fee-proxy-contract', ()
);
}).toThrowError(`The request must have a payee`);
});

it('cannot applyActionToExtensions of addFee signed by someone else than the payee', () => {
const previousState = Utils.deepCopy(DataConversionERC20FeeCreate.requestStateCreatedEmpty);
expect(() => {
Expand All @@ -692,7 +711,7 @@ describe('extensions/payment-network/erc20/any-to-erc20-fee-proxy-contract', ()
);
}).toThrowError(`The signer must be the payee`);
});

it('cannot applyActionToExtensions of addFee with fee data already given', () => {
expect(() => {
anyToErc20Proxy.applyActionToExtension(
Expand All @@ -704,7 +723,7 @@ describe('extensions/payment-network/erc20/any-to-erc20-fee-proxy-contract', ()
);
}).toThrowError(`Fee address already given`);
});

it('cannot applyActionToExtensions of addFee with fee address not valid', () => {
const testnetPaymentAddress = Utils.deepCopy(DataConversionERC20FeeAddData.actionAddFee);
testnetPaymentAddress.parameters.feeAddress = DataConversionERC20FeeAddData.invalidAddress;
Expand All @@ -718,10 +737,10 @@ describe('extensions/payment-network/erc20/any-to-erc20-fee-proxy-contract', ()
);
}).toThrowError('feeAddress is not a valid address');
});

it('cannot applyActionToExtensions of addFee with fee amount not valid', () => {
const testnetPaymentAddress = Utils.deepCopy(DataConversionERC20FeeAddData.actionAddFee);
testnetPaymentAddress.parameters.feeAmount = "invalid amount";
testnetPaymentAddress.parameters.feeAmount = 'invalid amount';
expect(() => {
anyToErc20Proxy.applyActionToExtension(
DataConversionERC20FeeCreate.requestStateCreatedEmpty.extensions,
Expand Down

0 comments on commit 9e3ab6d

Please sign in to comment.