-
Notifications
You must be signed in to change notification settings - Fork 25
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
118 additions
and
107 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,127 +1,135 @@ | ||
import { GreaterThanOrEqual, apply } from '@rabbitholegg/questdk/filter' | ||
import { describe, expect, test } from 'vitest' | ||
import { bridge } from './Optimism.js' | ||
import { l1StandardBridgeABI, l2StandardBridgeABI, addresses } from '@eth-optimism/contracts-ts' | ||
import {DEPOSIT_ETH, DEPOSIT_TETHER, WITHDRAW_ETH, WITHDRAW_USDC} from './test-transactions.js' | ||
import { ETH_TOKEN_ADDRESS, USDC_TOKEN_ADDRESS, TETHER_TOKEN_ADDRESS } from './token-addresses' | ||
import { | ||
l1StandardBridgeABI, | ||
l2StandardBridgeABI, | ||
addresses, | ||
} from '@eth-optimism/contracts-ts' | ||
import { | ||
DEPOSIT_ETH, | ||
DEPOSIT_TETHER, | ||
WITHDRAW_ETH, | ||
WITHDRAW_USDC, | ||
} from './test-transactions.js' | ||
import { | ||
ETH_TOKEN_ADDRESS, | ||
USDC_TOKEN_ADDRESS, | ||
TETHER_TOKEN_ADDRESS, | ||
} from './token-addresses' | ||
import { parseEther } from 'viem' | ||
|
||
// Replace *project* with the name of the project | ||
describe('Given the optimism plugin', () => { | ||
describe('When generating the filter', () => { | ||
test('should return a valid bridge action filter for L2 token tx', async () => { | ||
const filter = await bridge({ | ||
sourceChainId: 10, | ||
destinationChainId: 1, | ||
tokenAddress: USDC_TOKEN_ADDRESS, | ||
amount: GreaterThanOrEqual(100000n), | ||
}) | ||
|
||
|
||
const filter = await bridge({ | ||
sourceChainId: 10, | ||
destinationChainId: 1, | ||
tokenAddress: USDC_TOKEN_ADDRESS, | ||
amount: GreaterThanOrEqual(100000n), | ||
}) | ||
|
||
expect(filter).to.deep.equal({ | ||
chainId: '0xa', | ||
to: addresses.L2StandardBridge[420], | ||
input: { | ||
$abi: l2StandardBridgeABI, | ||
_l2Token: USDC_TOKEN_ADDRESS, | ||
_amount: { | ||
$gte: '100000', | ||
}, | ||
expect(filter).to.deep.equal({ | ||
chainId: '0xa', | ||
to: addresses.L2StandardBridge[420], | ||
input: { | ||
$abi: l2StandardBridgeABI, | ||
_l2Token: USDC_TOKEN_ADDRESS, | ||
_amount: { | ||
$gte: '100000', | ||
}, | ||
}) | ||
}, | ||
}) | ||
}) | ||
|
||
test('should return a valid bridge action filter for L1 token tx', async () => { | ||
|
||
const filter = await bridge({ | ||
sourceChainId: 1, | ||
destinationChainId: 10, | ||
tokenAddress: USDC_TOKEN_ADDRESS, | ||
amount: GreaterThanOrEqual(100000n), | ||
}) | ||
|
||
expect(filter).to.deep.equal({ | ||
chainId: '0x1', | ||
to: addresses.L1StandardBridge[1], | ||
input: { | ||
$abi: l1StandardBridgeABI, | ||
_l1Token: USDC_TOKEN_ADDRESS, | ||
_amount: { | ||
$gte: '100000', | ||
}, | ||
}, | ||
}) | ||
test('should return a valid bridge action filter for L1 token tx', async () => { | ||
const filter = await bridge({ | ||
sourceChainId: 1, | ||
destinationChainId: 10, | ||
tokenAddress: USDC_TOKEN_ADDRESS, | ||
amount: GreaterThanOrEqual(100000n), | ||
}) | ||
|
||
test('should return a valid bridge action filter for L1 ETH tx', async () => { | ||
const filter = await bridge({ | ||
sourceChainId: 1, | ||
destinationChainId: 10, | ||
tokenAddress: ETH_TOKEN_ADDRESS, | ||
amount: GreaterThanOrEqual(100000n), | ||
}) | ||
|
||
expect(filter).to.deep.equal({ | ||
chainId: '0x1', | ||
to: addresses.L1StandardBridge[1], | ||
value: { | ||
expect(filter).to.deep.equal({ | ||
chainId: '0x1', | ||
to: addresses.L1StandardBridge[1], | ||
input: { | ||
$abi: l1StandardBridgeABI, | ||
_l1Token: USDC_TOKEN_ADDRESS, | ||
_amount: { | ||
$gte: '100000', | ||
}, | ||
input: { | ||
$abi: l1StandardBridgeABI, | ||
}, | ||
}) | ||
}, | ||
}) | ||
}) | ||
describe('When applying the filter', () => { | ||
|
||
test('should pass filter with valid L1 ETH tx', async() => { | ||
const transaction = DEPOSIT_ETH; | ||
const filter = await bridge({ | ||
sourceChainId: 1, | ||
destinationChainId: 10, // Optimism | ||
tokenAddress: ETH_TOKEN_ADDRESS, | ||
amount: GreaterThanOrEqual(parseEther('.2')), | ||
}) | ||
|
||
expect(apply(transaction, filter)).to.be.true | ||
test('should return a valid bridge action filter for L1 ETH tx', async () => { | ||
const filter = await bridge({ | ||
sourceChainId: 1, | ||
destinationChainId: 10, | ||
tokenAddress: ETH_TOKEN_ADDRESS, | ||
amount: GreaterThanOrEqual(100000n), | ||
}) | ||
|
||
expect(filter).to.deep.equal({ | ||
chainId: '0x1', | ||
to: addresses.L1StandardBridge[1], | ||
value: { | ||
$gte: '100000', | ||
}, | ||
input: { | ||
$abi: l1StandardBridgeABI, | ||
}, | ||
}) | ||
}) | ||
test('should pass filter with valid L1 Token tx', async() => { | ||
const transaction = DEPOSIT_TETHER; | ||
const filter = await bridge({ | ||
sourceChainId: 1, | ||
destinationChainId: 10, // Optimism | ||
tokenAddress: TETHER_TOKEN_ADDRESS, | ||
amount: GreaterThanOrEqual('85000000'), | ||
}) | ||
|
||
expect(apply(transaction, filter)).to.be.true | ||
}) | ||
describe('When applying the filter', () => { | ||
test('should pass filter with valid L1 ETH tx', async () => { | ||
const transaction = DEPOSIT_ETH | ||
const filter = await bridge({ | ||
sourceChainId: 1, | ||
destinationChainId: 10, // Optimism | ||
tokenAddress: ETH_TOKEN_ADDRESS, | ||
amount: GreaterThanOrEqual(parseEther('.2')), | ||
}) | ||
|
||
expect(apply(transaction, filter)).to.be.true | ||
}) | ||
test('should pass filter with valid L2 ETH tx', async() => { | ||
const transaction = WITHDRAW_ETH; | ||
const filter = await bridge({ | ||
sourceChainId: 10, | ||
destinationChainId: 1, // Optimism | ||
tokenAddress: ETH_TOKEN_ADDRESS, | ||
amount: GreaterThanOrEqual(parseEther('37')), | ||
}) | ||
expect(apply(transaction, filter)).to.be.true | ||
test('should pass filter with valid L1 Token tx', async () => { | ||
const transaction = DEPOSIT_TETHER | ||
const filter = await bridge({ | ||
sourceChainId: 1, | ||
destinationChainId: 10, // Optimism | ||
tokenAddress: TETHER_TOKEN_ADDRESS, | ||
amount: GreaterThanOrEqual('85000000'), | ||
}) | ||
|
||
expect(apply(transaction, filter)).to.be.true | ||
}) | ||
test('should pass filter with valid L2 token tx', async() => { | ||
const transaction = WITHDRAW_USDC; | ||
const filter = await bridge({ | ||
sourceChainId: 10, | ||
destinationChainId: 1, // Optimism | ||
tokenAddress: USDC_TOKEN_ADDRESS, | ||
amount: GreaterThanOrEqual(10000000), | ||
}) | ||
expect(apply(transaction, filter)).to.be.true | ||
test('should pass filter with valid L2 ETH tx', async () => { | ||
const transaction = WITHDRAW_ETH | ||
const filter = await bridge({ | ||
sourceChainId: 10, | ||
destinationChainId: 1, // Optimism | ||
tokenAddress: ETH_TOKEN_ADDRESS, | ||
amount: GreaterThanOrEqual(parseEther('37')), | ||
}) | ||
|
||
expect(apply(transaction, filter)).to.be.true | ||
}) | ||
test('should pass filter with valid L2 token tx', async () => { | ||
const transaction = WITHDRAW_USDC | ||
const filter = await bridge({ | ||
sourceChainId: 10, | ||
destinationChainId: 1, // Optimism | ||
tokenAddress: USDC_TOKEN_ADDRESS, | ||
amount: GreaterThanOrEqual(10000000), | ||
}) | ||
|
||
expect(apply(transaction, filter)).to.be.true | ||
}) | ||
|
||
}) | ||
|
||
test('should not pass filter with invalid transactions', () => {}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,3 @@ | ||
export const ETH_TOKEN_ADDRESS = '0xdeaddeaddeaddeaddeaddeaddeaddeaddead0000'; | ||
export const USDC_TOKEN_ADDRESS = '0x7F5c764cBc14f9669B88837ca1490cCa17c31607'; | ||
export const TETHER_TOKEN_ADDRESS = '0xdAC17F958D2ee523a2206206994597C13D831ec7'; | ||
|
||
export const ETH_TOKEN_ADDRESS = '0xdeaddeaddeaddeaddeaddeaddeaddeaddead0000' | ||
export const USDC_TOKEN_ADDRESS = '0x7F5c764cBc14f9669B88837ca1490cCa17c31607' | ||
export const TETHER_TOKEN_ADDRESS = '0xdAC17F958D2ee523a2206206994597C13D831ec7' |