Authorize sender adddress
This commit is contained in:
parent
282930cb9b
commit
cdbcada49b
@ -75,6 +75,7 @@ contract DexForwarderBridge is
|
|||||||
freesGasTokensFromCollector
|
freesGasTokensFromCollector
|
||||||
returns (bytes4 success)
|
returns (bytes4 success)
|
||||||
{
|
{
|
||||||
|
require(msg.sender == _getERC20BridgeProxyAddress(), "DexForwarderBridge/SENDER_NOT_AUTHORIZED");
|
||||||
TransferFromState memory state;
|
TransferFromState memory state;
|
||||||
(
|
(
|
||||||
state.inputToken,
|
state.inputToken,
|
||||||
|
@ -156,6 +156,13 @@ contract TestDexForwarderBridge is
|
|||||||
ITestDexForwarderBridge,
|
ITestDexForwarderBridge,
|
||||||
DexForwarderBridge
|
DexForwarderBridge
|
||||||
{
|
{
|
||||||
|
address private AUTHORIZED_ADDRESS; // solhint-disable-line var-name-mixedcase
|
||||||
|
|
||||||
|
function setAuthorized(address authorized)
|
||||||
|
public
|
||||||
|
{
|
||||||
|
AUTHORIZED_ADDRESS = authorized;
|
||||||
|
}
|
||||||
|
|
||||||
function createBridge(
|
function createBridge(
|
||||||
bytes4 returnCode,
|
bytes4 returnCode,
|
||||||
@ -226,4 +233,12 @@ contract TestDexForwarderBridge is
|
|||||||
{
|
{
|
||||||
return address(0);
|
return address(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function _getERC20BridgeProxyAddress()
|
||||||
|
internal
|
||||||
|
view
|
||||||
|
returns (address erc20BridgeProxyAddress)
|
||||||
|
{
|
||||||
|
return AUTHORIZED_ADDRESS;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -8,7 +8,7 @@ import {
|
|||||||
randomAddress,
|
randomAddress,
|
||||||
shortZip,
|
shortZip,
|
||||||
} from '@0x/contracts-test-utils';
|
} from '@0x/contracts-test-utils';
|
||||||
import { BigNumber, hexUtils } from '@0x/utils';
|
import { BigNumber, hexUtils, NULL_ADDRESS } from '@0x/utils';
|
||||||
import { DecodedLogs } from 'ethereum-types';
|
import { DecodedLogs } from 'ethereum-types';
|
||||||
import * as _ from 'lodash';
|
import * as _ from 'lodash';
|
||||||
|
|
||||||
@ -31,6 +31,7 @@ blockchainTests.resets('DexForwarderBridge unit tests', env => {
|
|||||||
const BRIDGE_FAILURE = '0xffffffff';
|
const BRIDGE_FAILURE = '0xffffffff';
|
||||||
const BRIDGE_REVERT_ERROR = 'oopsie';
|
const BRIDGE_REVERT_ERROR = 'oopsie';
|
||||||
const INCOMPLETE_FILL_REVERT = 'DexForwarderBridge/INCOMPLETE_FILL';
|
const INCOMPLETE_FILL_REVERT = 'DexForwarderBridge/INCOMPLETE_FILL';
|
||||||
|
const NOT_AUTHORIZED_REVERT = 'DexForwarderBridge/SENDER_NOT_AUTHORIZED';
|
||||||
const DEFAULTS = {
|
const DEFAULTS = {
|
||||||
toAddress: randomAddress(),
|
toAddress: randomAddress(),
|
||||||
};
|
};
|
||||||
@ -47,6 +48,7 @@ blockchainTests.resets('DexForwarderBridge unit tests', env => {
|
|||||||
await callAndTransactAsync(testContract.createToken()),
|
await callAndTransactAsync(testContract.createToken()),
|
||||||
await callAndTransactAsync(testContract.createToken()),
|
await callAndTransactAsync(testContract.createToken()),
|
||||||
];
|
];
|
||||||
|
await callAndTransactAsync(testContract.setAuthorized(env.txDefaults.from as string));
|
||||||
});
|
});
|
||||||
|
|
||||||
async function callAndTransactAsync<TResult>(fnCall: ContractTxFunctionObj<TResult>): Promise<TResult> {
|
async function callAndTransactAsync<TResult>(fnCall: ContractTxFunctionObj<TResult>): Promise<TResult> {
|
||||||
@ -186,6 +188,18 @@ blockchainTests.resets('DexForwarderBridge unit tests', env => {
|
|||||||
).to.revertWith(INCOMPLETE_FILL_REVERT);
|
).to.revertWith(INCOMPLETE_FILL_REVERT);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('fails if not authorized', async () => {
|
||||||
|
const calls = goodBridgeCalls.slice(0, 1);
|
||||||
|
const bridgeData = dexForwarderBridgeDataEncoder.encode({
|
||||||
|
inputToken,
|
||||||
|
calls,
|
||||||
|
});
|
||||||
|
await callAndTransactAsync(testContract.setAuthorized(NULL_ADDRESS));
|
||||||
|
return expect(callBridgeTransferFromAsync({ bridgeData, sellAmount: new BigNumber(1) })).to.revertWith(
|
||||||
|
NOT_AUTHORIZED_REVERT,
|
||||||
|
);
|
||||||
|
});
|
||||||
|
|
||||||
it('succeeds with one bridge call', async () => {
|
it('succeeds with one bridge call', async () => {
|
||||||
const calls = goodBridgeCalls.slice(0, 1);
|
const calls = goodBridgeCalls.slice(0, 1);
|
||||||
const bridgeData = dexForwarderBridgeDataEncoder.encode({
|
const bridgeData = dexForwarderBridgeDataEncoder.encode({
|
||||||
|
Loading…
x
Reference in New Issue
Block a user