Skip to content

Commit 126d124

Browse files
committed
test: add test for calling contracts that don't implement onTokenTransfer
1 parent 394458d commit 126d124

File tree

1 file changed

+25
-1
lines changed

1 file changed

+25
-1
lines changed

test/l2/l2GraphTokenGateway.test.ts

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ use(smock.matchers)
1414
import { getAccounts, toGRT, Account, toBN, getL2SignerFromL1 } from '../lib/testHelpers'
1515
import { Interface } from 'ethers/lib/utils'
1616
import { deployContract } from '../lib/deployment'
17+
import { RewardsManager } from '../../build/types/RewardsManager'
1718

1819
const { AddressZero } = constants
1920

@@ -34,6 +35,7 @@ describe('L2GraphTokenGateway', () => {
3435
let grt: L2GraphToken
3536
let l2GraphTokenGateway: L2GraphTokenGateway
3637
let callhookReceiverMock: CallhookReceiverMock
38+
let rewardsManager: RewardsManager
3739

3840
const senderTokens = toGRT('1000')
3941
const defaultData = '0x'
@@ -61,7 +63,7 @@ describe('L2GraphTokenGateway', () => {
6163

6264
fixture = new NetworkFixture()
6365
fixtureContracts = await fixture.loadL2(governor.signer)
64-
;({ grt, l2GraphTokenGateway } = fixtureContracts)
66+
;({ grt, l2GraphTokenGateway, rewardsManager } = fixtureContracts)
6567

6668
callhookReceiverMock = (await deployContract(
6769
'CallhookReceiverMock',
@@ -408,6 +410,28 @@ describe('L2GraphTokenGateway', () => {
408410
)
409411
await expect(tx).revertedWith('FOO_IS_ZERO')
410412
})
413+
it('reverts if trying to call a callhook in a contract that does not implement onTokenTransfer', async function () {
414+
const callHookData = utils.defaultAbiCoder.encode(['uint256'], [toBN('0')])
415+
const data = utils.defaultAbiCoder.encode(['bytes', 'bytes'], ['0x', callHookData])
416+
const mockL1GatewayL2Alias = await getL2SignerFromL1(mockL1Gateway.address)
417+
await me.signer.sendTransaction({
418+
to: await mockL1GatewayL2Alias.getAddress(),
419+
value: utils.parseUnits('1', 'ether'),
420+
})
421+
// RewardsManager does not implement onTokenTransfer, so this will fail
422+
const tx = l2GraphTokenGateway
423+
.connect(mockL1GatewayL2Alias)
424+
.finalizeInboundTransfer(
425+
mockL1GRT.address,
426+
tokenSender.address,
427+
rewardsManager.address,
428+
toGRT('10'),
429+
data,
430+
)
431+
await expect(tx).revertedWith(
432+
"function selector was not recognized and there's no fallback function",
433+
)
434+
})
411435
})
412436
})
413437
})

0 commit comments

Comments
 (0)