Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
N
nebula
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
exchain
nebula
Commits
29c54510
Commit
29c54510
authored
May 18, 2023
by
James Kim
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
run linter
parent
49e44329
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
44 additions
and
33 deletions
+44
-33
bridgeEcoToken.spec.ts
packages/sdk/test-next/bridgeEcoToken.spec.ts
+40
-23
ethersProviders.ts
packages/sdk/test-next/testUtils/ethersProviders.ts
+1
-4
viemClients.ts
packages/sdk/test-next/testUtils/viemClients.ts
+3
-6
No files found.
packages/sdk/test-next/bridgeEcoToken.spec.ts
View file @
29c54510
import
ethers
from
'
ethers
'
import
{
describe
,
expect
,
it
}
from
'
vitest
'
import
{
Address
,
PublicClient
,
parseEther
}
from
'
viem
'
import
{
l1TestClient
,
l2TestClient
,
l1PublicClient
,
l2PublicClient
,
}
from
'
./testUtils/viemClients
'
import
{
BRIDGE_ADAPTER_DATA
,
CrossChainMessenger
,
DEPOSIT_CONFIRMATION_BLOCKS
,
L2ChainID
}
from
'
../src
'
import
{
Address
,
PublicClient
,
parseEther
}
from
'
viem
'
import
{
BRIDGE_ADAPTER_DATA
,
CrossChainMessenger
,
L2ChainID
}
from
'
../src
'
import
{
l1Provider
,
l2Provider
}
from
'
./testUtils/ethersProviders
'
const
ECO_WHALE
:
Address
=
'
0xBd11c836279a1352ce737FbBFba36b20734B04e7
'
// we should instead use tokenlist as source of truth
const
ECO_L1_TOKEN_ADDRESS
:
Address
=
'
0x3E87d4d9E69163E7590f9b39a70853cf25e5ABE3
'
const
ECO_L2_TOKEN_ADDRESS
:
Address
=
'
0x54bBECeA38ff36D32323f8A754683C1F5433A89f
'
const
getERC20TokenBalance
=
async
(
publicClient
:
PublicClient
,
tokenAddress
:
Address
,
ownerAddress
:
Address
)
=>
{
const
ECO_L1_TOKEN_ADDRESS
:
Address
=
'
0x3E87d4d9E69163E7590f9b39a70853cf25e5ABE3
'
const
ECO_L2_TOKEN_ADDRESS
:
Address
=
'
0x54bBECeA38ff36D32323f8A754683C1F5433A89f
'
const
getERC20TokenBalance
=
async
(
publicClient
:
PublicClient
,
tokenAddress
:
Address
,
ownerAddress
:
Address
)
=>
{
const
result
=
await
publicClient
.
readContract
({
address
:
tokenAddress
,
abi
:
[
...
...
@@ -27,28 +33,36 @@ const getERC20TokenBalance = async (publicClient: PublicClient, tokenAddress: Ad
outputs
:
[{
name
:
''
,
type
:
'
uint256
'
}],
stateMutability
:
'
view
'
,
type
:
'
function
'
,
}
}
,
],
functionName
:
'
balanceOf
'
,
args
:
[
ownerAddress
]
args
:
[
ownerAddress
]
,
})
return
result
as
bigint
}
const
getL1ERC20TokenBalance
=
async
(
ownerAddress
:
Address
)
=>
{
return
getERC20TokenBalance
(
l1PublicClient
,
ECO_L1_TOKEN_ADDRESS
,
ownerAddress
)
return
getERC20TokenBalance
(
l1PublicClient
,
ECO_L1_TOKEN_ADDRESS
,
ownerAddress
)
}
const
getL2ERC20TokenBalance
=
async
(
ownerAddress
:
Address
)
=>
{
return
getERC20TokenBalance
(
l2PublicClient
,
ECO_L2_TOKEN_ADDRESS
,
ownerAddress
)
return
getERC20TokenBalance
(
l2PublicClient
,
ECO_L2_TOKEN_ADDRESS
,
ownerAddress
)
}
describe
(
'
ECO token
'
,
()
=>
{
it
(
'
sdk should be able to deposit to l1 bridge contract correctly
'
,
async
()
=>
{
await
l1TestClient
.
impersonateAccount
({
address
:
ECO_WHALE
})
const
l1EcoWhaleSigner
=
await
l1Provider
.
getSigner
(
ECO_WHALE
)
;
const
l1EcoWhaleSigner
=
await
l1Provider
.
getSigner
(
ECO_WHALE
)
const
preBridgeL1EcoWhaleBalance
=
await
getL1ERC20TokenBalance
(
ECO_WHALE
)
const
crossChainMessenger
=
new
CrossChainMessenger
({
...
...
@@ -57,30 +71,32 @@ describe('ECO token', () => {
l1ChainId
:
5
,
l2ChainId
:
420
,
bedrock
:
true
,
bridges
:
BRIDGE_ADAPTER_DATA
[
L2ChainID
.
OPTIMISM_GOERLI
]
bridges
:
BRIDGE_ADAPTER_DATA
[
L2ChainID
.
OPTIMISM_GOERLI
]
,
})
await
crossChainMessenger
.
approveERC20
(
ECO_L1_TOKEN_ADDRESS
,
ECO_L2_TOKEN_ADDRESS
,
ethers
.
utils
.
parseEther
(
'
0.1
'
)
,
ethers
.
utils
.
parseEther
(
'
0.1
'
)
)
const
txResponse
=
await
crossChainMessenger
.
depositERC20
(
ECO_L1_TOKEN_ADDRESS
,
ECO_L2_TOKEN_ADDRESS
,
ethers
.
utils
.
parseEther
(
'
0.1
'
)
,
ethers
.
utils
.
parseEther
(
'
0.1
'
)
)
await
txResponse
.
wait
()
;
await
txResponse
.
wait
()
const
l1EcoWhaleBalance
=
await
getL1ERC20TokenBalance
(
ECO_WHALE
)
expect
(
l1EcoWhaleBalance
).
toEqual
(
preBridgeL1EcoWhaleBalance
-
parseEther
(
'
0.1
'
))
expect
(
l1EcoWhaleBalance
).
toEqual
(
preBridgeL1EcoWhaleBalance
-
parseEther
(
'
0.1
'
)
)
},
20
_000
)
it
(
'
sdk should be able to withdraw into the l2 bridge contract correctly
'
,
async
()
=>
{
await
l2TestClient
.
impersonateAccount
({
address
:
ECO_WHALE
})
const
l2EcoWhaleSigner
=
await
l2Provider
.
getSigner
(
ECO_WHALE
)
;
const
l2EcoWhaleSigner
=
await
l2Provider
.
getSigner
(
ECO_WHALE
)
const
preBridgeL2EcoWhaleBalance
=
await
getL2ERC20TokenBalance
(
ECO_WHALE
)
...
...
@@ -90,19 +106,20 @@ describe('ECO token', () => {
l1ChainId
:
5
,
l2ChainId
:
420
,
bedrock
:
true
,
bridges
:
BRIDGE_ADAPTER_DATA
[
L2ChainID
.
OPTIMISM_GOERLI
]
bridges
:
BRIDGE_ADAPTER_DATA
[
L2ChainID
.
OPTIMISM_GOERLI
]
,
})
const
txResponse
=
await
crossChainMessenger
.
withdrawERC20
(
ECO_L1_TOKEN_ADDRESS
,
ECO_L2_TOKEN_ADDRESS
,
ethers
.
utils
.
parseEther
(
'
0.1
'
)
,
ethers
.
utils
.
parseEther
(
'
0.1
'
)
)
await
txResponse
.
wait
()
;
await
txResponse
.
wait
()
const
l2EcoWhaleBalance
=
await
getL2ERC20TokenBalance
(
ECO_WHALE
)
expect
(
l2EcoWhaleBalance
).
toEqual
(
preBridgeL2EcoWhaleBalance
-
parseEther
(
'
0.1
'
))
expect
(
l2EcoWhaleBalance
).
toEqual
(
preBridgeL2EcoWhaleBalance
-
parseEther
(
'
0.1
'
)
)
},
20
_000
)
})
packages/sdk/test-next/testUtils/ethersProviders.ts
View file @
29c54510
...
...
@@ -25,7 +25,4 @@ const l2Provider = new ethers.providers.JsonRpcProvider({
headers
:
jsonRpcHeaders
,
})
export
{
l1Provider
,
l2Provider
}
export
{
l1Provider
,
l2Provider
}
packages/sdk/test-next/testUtils/viemClients.ts
View file @
29c54510
...
...
@@ -7,9 +7,9 @@ import {
import
{
goerli
,
optimismGoerli
}
from
'
viem/chains
'
// we should instead use env vars to determine chain so we can support alternate l1/l2 pairs
const
L1_CHAIN
=
goerli
;
const
L2_CHAIN
=
optimismGoerli
;
const
L1_RPC_URL
=
'
http://localhost:8545
'
;
const
L1_CHAIN
=
goerli
const
L2_CHAIN
=
optimismGoerli
const
L1_RPC_URL
=
'
http://localhost:8545
'
const
L2_RPC_URL
=
'
http://localhost:9545
'
const
l1TestClient
=
createTestClient
({
...
...
@@ -18,20 +18,17 @@ const l1TestClient = createTestClient({
transport
:
http
(
L1_RPC_URL
),
})
const
l2TestClient
=
createTestClient
({
mode
:
'
anvil
'
,
chain
:
L2_CHAIN
,
transport
:
http
(
L2_RPC_URL
),
})
const
l1PublicClient
=
createPublicClient
({
chain
:
L1_CHAIN
,
transport
:
http
(
L1_RPC_URL
),
})
const
l2PublicClient
=
createPublicClient
({
chain
:
L2_CHAIN
,
transport
:
http
(
L2_RPC_URL
),
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment