Skip to content

Commit

Permalink
formatting (#22)
Browse files Browse the repository at this point in the history
  • Loading branch information
wilsoncusack authored Aug 27, 2023
1 parent 2ceb3a2 commit 6c37f3e
Show file tree
Hide file tree
Showing 7 changed files with 73 additions and 56 deletions.
3 changes: 1 addition & 2 deletions src/_test/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,6 @@ export const poolId = Number(process.env.VITEST_POOL_ID ?? 1)
export const localHttpUrl = `http://127.0.0.1:8545/${poolId}`
export const localWsUrl = `ws://127.0.0.1:8545/${poolId}`


const messages = new Map()
function warn(message: string) {
if (!messages.has(message)) {
Expand Down Expand Up @@ -80,4 +79,4 @@ if (process.env.VITE_ANVIL_BLOCK_TIME) {
} else {
blockTime = 1
warn(`\`VITE_ANVIL_BLOCK_TIME\` not found. Falling back to \`${blockTime}\`.`)
}
}
2 changes: 1 addition & 1 deletion src/_test/globalSetup.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,4 +33,4 @@ export default async function () {
blockTime,
},
})
}
}
3 changes: 1 addition & 2 deletions src/actions/public/getWithdrawalMessages.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,7 @@ test('correctly retrieves L2 hash', async () => {
}).extend(publicOpStackActions)

const messages = await client.getWithdrawalMessages({
hash:
'0x999bab960dbdf600c51371ae819957063337a50cec2eb8032412739defadabe7',
hash: '0x999bab960dbdf600c51371ae819957063337a50cec2eb8032412739defadabe7',
})
expect(messages.length).toEqual(1)
expect(messages[0].nonce).toBeDefined()
Expand Down
24 changes: 16 additions & 8 deletions src/actions/public/getWithdrawalMessages.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,21 @@
import { type PublicClient, Chain, Transport, Hash, Address, Hex, decodeEventLog } from 'viem'
import {
type PublicClient,
Chain,
Transport,
Hash,
Address,
Hex,
decodeEventLog,
} from 'viem'
import { l2ToL1MessagePasserABI } from '@eth-optimism/contracts-ts'

export type MessagePassedEvent = {
nonce: bigint,
sender: Address,
target: Address,
value: bigint,
gasLimit: bigint,
data: Hex,
nonce: bigint
sender: Address
target: Address
value: bigint
gasLimit: bigint
data: Hex
withdrawalHash: Hex
}

Expand Down Expand Up @@ -45,5 +53,5 @@ export async function getWithdrawalMessages<TChain extends Chain | undefined>(
}
} catch {}
}
return events;
return events
}
89 changes: 48 additions & 41 deletions src/actions/wallet/writeUnsafeDepositTransaction.test.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
import { expect, test } from 'vitest'
import { publicClient, walletClient, testClient } from '../../_test/utils'
import { DepositTransactionParameters, writeUnsafeDepositTransaction } from './writeUnsafeDepositTransaction'
import {
DepositTransactionParameters,
writeUnsafeDepositTransaction,
} from './writeUnsafeDepositTransaction'
import { base } from '@roninjin10/rollup-chains'
import { accounts, } from '../../_test/constants'
import { accounts } from '../../_test/constants'
import { mine } from 'viem/actions'
import { encodeFunctionData } from 'viem'
import { optimismPortalABI } from '@eth-optimism/contracts-ts'
Expand All @@ -24,21 +27,21 @@ test('default', async () => {
})

test('sends transaction to correct address', async () => {
const hash = await writeUnsafeDepositTransaction(walletClient, {
args: {
to: '0x0c54fccd2e384b4bb6f2e405bf5cbc15a017aafb',
value: 1n,
gasLimit: 1n,
data: '0x',
isCreation: false,
},
toChain: base,
account: accounts[0].address,
})
const hash = await writeUnsafeDepositTransaction(walletClient, {
args: {
to: '0x0c54fccd2e384b4bb6f2e405bf5cbc15a017aafb',
value: 1n,
gasLimit: 1n,
data: '0x',
isCreation: false,
},
toChain: base,
account: accounts[0].address,
})

await mine(testClient, { blocks: 1 })

const r = await publicClient.getTransactionReceipt({hash});
const r = await publicClient.getTransactionReceipt({ hash })
expect(r.to).toEqual(base.opContracts.OptimismPortalProxy.toLocaleLowerCase())
})

Expand All @@ -51,42 +54,46 @@ test('correctly passes arugments', async () => {
gasLimit: 1n,
data: '0x',
isCreation: false,
};
}

const hash = await writeUnsafeDepositTransaction(walletClient, {
args,
toChain: base,
account: accounts[0].address,
})

const hash = await writeUnsafeDepositTransaction(walletClient, {
args,
toChain: base,
account: accounts[0].address,
})

await mine(testClient, { blocks: 1 })

const t = await publicClient.getTransaction({hash});
expect(t.input).toEqual(encodeFunctionData({
abi: optimismPortalABI,
functionName: 'depositTransaction',
args: [args.to, args.value!, args.gasLimit, args.isCreation!, args.data!]
}))
const t = await publicClient.getTransaction({ hash })
expect(t.input).toEqual(
encodeFunctionData({
abi: optimismPortalABI,
functionName: 'depositTransaction',
args: [args.to, args.value!, args.gasLimit, args.isCreation!, args.data!],
}),
)
})

test('uses defaults for data, isCreation, and value', async () => {
const args: DepositTransactionParameters = {
to: '0x0c54fccd2e384b4bb6f2e405bf5cbc15a017aafb',
gasLimit: 1n,
};
}

const hash = await writeUnsafeDepositTransaction(walletClient, {
args,
toChain: base,
account: accounts[0].address,
})

const hash = await writeUnsafeDepositTransaction(walletClient, {
args,
toChain: base,
account: accounts[0].address,
})

await mine(testClient, { blocks: 1 })

const t = await publicClient.getTransaction({hash});
expect(t.input).toEqual(encodeFunctionData({
abi: optimismPortalABI,
functionName: 'depositTransaction',
args: [args.to, 0n, args.gasLimit, false, '0x']
}))
const t = await publicClient.getTransaction({ hash })
expect(t.input).toEqual(
encodeFunctionData({
abi: optimismPortalABI,
functionName: 'depositTransaction',
args: [args.to, 0n, args.gasLimit, false, '0x'],
}),
)
})
6 changes: 5 additions & 1 deletion src/decorators/publicOpStack.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,11 @@ import {
GetL2HashesForDepositTxReturnType,
getL2HashesForDepositTx,
} from '../actions/public/getL2HashesForDepositTx'
import { GetWithdrawalMessagesParameters, GetWithdrawalMessagesReturnType, getWithdrawalMessages } from '../actions/public/getWithdrawalMessages'
import {
GetWithdrawalMessagesParameters,
GetWithdrawalMessagesReturnType,
getWithdrawalMessages,
} from '../actions/public/getWithdrawalMessages'

/// NOTE We don't currently need account for exisiting actions but keeping in case
export type PublicOpStackActions<
Expand Down
2 changes: 1 addition & 1 deletion vitest.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,4 +22,4 @@ export default defineConfig({
globalSetup: ['./src/_test/globalSetup.ts'],
testTimeout: 10_000,
},
})
})

0 comments on commit 6c37f3e

Please sign in to comment.