Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: update depositTo to use standard deposit #432

Merged
merged 27 commits into from
Apr 30, 2024
Merged
Show file tree
Hide file tree
Changes from 23 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 0 additions & 2 deletions .github/workflows/build-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -161,8 +161,6 @@ jobs:
- name: Set up the local node
uses: OffchainLabs/actions/run-nitro-test-node@main
with:
nitro-testnode-ref: release
nitro-contracts-branch: validator-wallet-fix
l3-node: ${{ matrix.orbit-test == '1' }}
args: ${{ matrix.custom-fee == '1' && '--l3-fee-token' || '' }}

Expand Down
10 changes: 6 additions & 4 deletions src/lib/assetBridger/ethBridger.ts
Original file line number Diff line number Diff line change
Expand Up @@ -352,10 +352,12 @@ export class EthBridger extends AssetBridger<
l1Provider: params.l1Signer.provider!,
})

const tx = await params.l1Signer.sendTransaction({
...retryableTicketRequest.txRequest,
...params.overrides,
})
const l1ToL2MessageCreator = new L1ToL2MessageCreator(params.l1Signer)

const tx = await l1ToL2MessageCreator.createRetryableTicket(
retryableTicketRequest,
params.l2Provider
)

return L1TransactionReceipt.monkeyPatchContractCallWait(tx)
}
Expand Down
61 changes: 60 additions & 1 deletion tests/integration/eth.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@

import { Wallet } from '@ethersproject/wallet'
import { parseEther } from '@ethersproject/units'
import { constants } from 'ethers'

import {
fundL1,
Expand All @@ -32,11 +33,15 @@
import { L2ToL1Message } from '../../src/lib/message/L2ToL1Message'
import { L2ToL1MessageStatus } from '../../src/lib/dataEntities/message'
import { L2TransactionReceipt } from '../../src/lib/message/L2Transaction'
import { L1ToL2MessageStatus } from '../../src/lib/message/L1ToL2Message'
import {
L1ToL2MessageStatus,
L1ToL2MessageWriter,
} from '../../src/lib/message/L1ToL2Message'
import { testSetup } from '../../scripts/testSetup'
import { isL2NetworkWithCustomFeeToken } from './custom-fee-token/customFeeTokenTestHelpers'
import { ERC20__factory } from '../../src/lib/abi/factories/ERC20__factory'
import { itOnlyWhenEth } from './custom-fee-token/mochaExtensions'
import { L1TransactionReceipt } from '../../src'

dotenv.config()

Expand Down Expand Up @@ -211,6 +216,60 @@
)
})

it('deposit ether to a specific L2 address and check balance before auto-redeem', async () => {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
it('deposit ether to a specific L2 address and check balance before auto-redeem', async () => {
it('deposit ether to a specific L2 address with manual redeem', async () => {

const { ethBridger, l1Signer, l2Signer } = await testSetup()

await fundL1(l1Signer)
const destWallet = Wallet.createRandom()

const ethToDeposit = parseEther('0.0002')
const res = await ethBridger.depositTo({
amount: ethToDeposit,
l1Signer: l1Signer,
destinationAddress: destWallet.address,
l2Provider: l2Signer.provider!,
retryableGasOverrides: {
gasLimit: {
// causes auto-redeem to fail which allows us to check balances before it happens
base: constants.Zero,
},
},
})
const rec = await res.wait()
const l1ToL2Messages = await rec.getL1ToL2Messages(l2Signer.provider!)
expect(l1ToL2Messages.length).to.eq(1, 'failed to find 1 l1 to l2 message')
let l1ToL2Message = l1ToL2Messages[0]
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
let l1ToL2Message = l1ToL2Messages[0]
const l1ToL2MessageReader = l1ToL2Messages[0]


const retryableTicketResult = await l1ToL2Message.waitForStatus()

expect(retryableTicketResult.status).to.eq(
L1ToL2MessageStatus.FUNDS_DEPOSITED_ON_L2,
'unexpected status, expected auto-redeem to fail'
)

const testWalletL2EthBalance = await l2Signer.provider!.getBalance(
destWallet.address
)
expect(
testWalletL2EthBalance.lt(ethToDeposit),
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lets assert it's zero

'balance before auto-redeem'
).to.be.true

const l1TxHash = await l1Signer.provider!.getTransactionReceipt(res.hash)
const l1Receipt = new L1TransactionReceipt(l1TxHash)
l1ToL2Message = l1Receipt.getL1ToL2Messages(l2Signer)[0]

Check failure on line 260 in tests/integration/eth.test.ts

View workflow job for this annotation

GitHub Actions / Test (Integration) on Node.js v16

Element implicitly has an 'any' type because expression of type '0' can't be used to index type 'Promise<L1ToL2MessageWriter[]>'.

Check failure on line 260 in tests/integration/eth.test.ts

View workflow job for this annotation

GitHub Actions / Test (Integration) on Node.js v16 with L3

Element implicitly has an 'any' type because expression of type '0' can't be used to index type 'Promise<L1ToL2MessageWriter[]>'.

Check failure on line 260 in tests/integration/eth.test.ts

View workflow job for this annotation

GitHub Actions / Test (Integration) on Node.js v18

Element implicitly has an 'any' type because expression of type '0' can't be used to index type 'Promise<L1ToL2MessageWriter[]>'.

Check failure on line 260 in tests/integration/eth.test.ts

View workflow job for this annotation

GitHub Actions / Test (Integration) on Node.js v18 with L3

Element implicitly has an 'any' type because expression of type '0' can't be used to index type 'Promise<L1ToL2MessageWriter[]>'.

Check failure on line 260 in tests/integration/eth.test.ts

View workflow job for this annotation

GitHub Actions / Test (Integration) on Node.js v20

Element implicitly has an 'any' type because expression of type '0' can't be used to index type 'Promise<L1ToL2MessageWriter[]>'.

Check failure on line 260 in tests/integration/eth.test.ts

View workflow job for this annotation

GitHub Actions / Test (Integration) on Node.js v20 with L3

Element implicitly has an 'any' type because expression of type '0' can't be used to index type 'Promise<L1ToL2MessageWriter[]>'.

Check failure on line 260 in tests/integration/eth.test.ts

View workflow job for this annotation

GitHub Actions / Test (Integration) on Node.js v16 with L3 with custom gas token

Element implicitly has an 'any' type because expression of type '0' can't be used to index type 'Promise<L1ToL2MessageWriter[]>'.

Check failure on line 260 in tests/integration/eth.test.ts

View workflow job for this annotation

GitHub Actions / Test (Integration) on Node.js v18 with L3 with custom gas token

Element implicitly has an 'any' type because expression of type '0' can't be used to index type 'Promise<L1ToL2MessageWriter[]>'.

Check failure on line 260 in tests/integration/eth.test.ts

View workflow job for this annotation

GitHub Actions / Test (Integration) on Node.js v20 with L3 with custom gas token

Element implicitly has an 'any' type because expression of type '0' can't be used to index type 'Promise<L1ToL2MessageWriter[]>'.

if (l1ToL2Message instanceof L1ToL2MessageWriter) {
const res = await l1ToL2Message.redeem()
await res.wait()
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
l1ToL2Message = l1Receipt.getL1ToL2Messages(l2Signer)[0]
if (l1ToL2Message instanceof L1ToL2MessageWriter) {
const res = await l1ToL2Message.redeem()
await res.wait()
}
const l1ToL2MessageWriter = l1Receipt.getL1ToL2Messages(l2Signer)[0]
await (await l1ToL2MessageWriter.redeem()).wait()


expect(
testWalletL2EthBalance.toString(),
'balance after manual redeem'
).to.eq(ethToDeposit.toString())
})

it('withdraw Ether transaction succeeds', async () => {
const { l2Signer, l1Signer, ethBridger } = await testSetup()
await fundL2(l2Signer)
Expand Down
Loading