-
Notifications
You must be signed in to change notification settings - Fork 3
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: test that deploy offchain in the layer 2. #53
Changes from all commits
83bffac
cd8ff41
52dc6fa
2030d77
188d10b
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
# Running Tests | ||
|
||
This project includes unit tests and end-to-end (E2E) tests. Below are the instructions to run the E2E tests. | ||
|
||
## Steps to Run E2E Tests | ||
|
||
1. In the terminal, navigate to the contracts directory: | ||
````cmd | ||
yarn contracts build | ||
```` | ||
|
||
2. Start the local Hardhat node: | ||
````cmd | ||
yarn hardhat node | ||
```` | ||
|
||
3. With the local Hardhat node running, execute the E2E tests: | ||
````cmd | ||
yarn client test | ||
```` | ||
|
||
|
||
# Running Tests with Local Arbitrum Node | ||
|
||
To run tests with a local Arbitrum node, follow the steps below: | ||
|
||
## Deploying a Local Node | ||
|
||
1. Open a new terminal for deploying the local node: | ||
|
||
### Step 1: Install prerequisites | ||
|
||
You'll need Docker and Docker Compose to run your node. Follow the instructions on their respective websites to install them. | ||
|
||
### Step 2: Clone the nitro-testnode repo | ||
|
||
You'll need the release branch. | ||
|
||
````bash | ||
git clone -b release --recurse-submodules https://github.com/OffchainLabs/nitro-testnode.git && cd nitro-testnode | ||
```` | ||
|
||
|
||
### Step 3: Run your node | ||
|
||
````bash | ||
./test-node.bash --init | ||
```` | ||
|
||
2. After deploying the local node, open another terminal and clone the external resolver from Blockful: | ||
|
||
````bash | ||
git clone https://github.com/blockful-io/external-resolver.git | ||
````` | ||
|
||
LeonardoVieira1630 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
3. Finally, run the tests: | ||
|
||
````bash | ||
yarn client hardhat test ./test/l2_e2e.spec.ts --network localhost | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. you could turn it into a script as well There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I tryed to use a script, but it was not possible to run the node and the tests in parallel. Maybe we can work on this improviment later. |
||
````` |
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -2,7 +2,7 @@ | |||||
"name": "@blockful/client", | ||||||
"packageManager": "yarn@4.1.0", | ||||||
"scripts": { | ||||||
"test": "vitest run", | ||||||
"test": "yarn hardhat test ./test/arbitrum_e2e.spec.ts --network localhost", | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
"test:watch": "vitest", | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. remove this line |
||||||
"start": "nodemon src/index.ts --resolver 0xe7f1725E7734CE288F8367e1Bb143E90bb3F0512", | ||||||
"lint": "eslint . --ext .ts --fix" | ||||||
|
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
@@ -0,0 +1,84 @@ | ||||||
/* | ||||||
This test script (e2e.spec.ts) aims to perform integrated testing of the project. It executes a series of actions, | ||||||
including deploying the contracts (registry, offchain resolver, and universal resolver), creating the Client using Viem, | ||||||
and initializing the gateway locally. After deploying and configuring the contracts, the Client can access | ||||||
off-chain information during the tests. It's important to note that this initial test script only sets up the | ||||||
environment and stops at the gateway call. It still requires implementing the connection between the gateway and | ||||||
layer two, or the gateway and the database. | ||||||
*/ | ||||||
|
||||||
// Importing abi and bytecode from contracts folder | ||||||
import { | ||||||
deployOffchainResolver, | ||||||
deployRegistry, | ||||||
deployUniversalResolver, | ||||||
} from './utils' | ||||||
import { ethers as eth } from 'hardhat' | ||||||
import { Wallet } from 'ethers' | ||||||
import { normalize } from 'viem/ens' | ||||||
import { localhost } from 'viem/chains' | ||||||
import { createTestClient, http, publicActions } from 'viem' | ||||||
const gatewayUrl = 'http://127.0.0.1:3000' | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
|
||||||
// Providers | ||||||
const l2Provider = new eth.JsonRpcProvider('http://127.0.0.1:8547') | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. try using viem instead: https://viem.sh/docs/ethers-migration#viem-1 |
||||||
const l1Provider = new eth.JsonRpcProvider('http://127.0.0.1:8545') | ||||||
const devAccountPrivateKey = | ||||||
'0xb6b15c8cb491557369f3c7d2c287b053eb229daa9c22138887752191c9520659' | ||||||
const devAccountPublicKey = '0x3f1Eae7D46d88F08fc2F8ed27FCb2AB183EB2d0E' | ||||||
|
||||||
describe('SeuContrato', () => { | ||||||
before(async () => { | ||||||
const signers = await eth.getSigners() | ||||||
|
||||||
const walletForL2 = new Wallet(devAccountPrivateKey) | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. try using viem instead: https://viem.sh/docs/ethers-migration#viem-11 |
||||||
const l2Signer = walletForL2.connect(l2Provider) | ||||||
const l1Signer = await l1Provider.getSigner(devAccountPublicKey) | ||||||
|
||||||
// Deploying the contracts | ||||||
const offchainResolverContract = await deployOffchainResolver( | ||||||
l2Signer, | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think this should be deployed on L1 and the PublicResolver on the L2 |
||||||
gatewayUrl, | ||||||
signers as unknown as string, | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. double-check this conversion |
||||||
) | ||||||
|
||||||
const RegistryContract = await deployRegistry( | ||||||
l1Signer, | ||||||
await offchainResolverContract.getAddress(), | ||||||
) | ||||||
|
||||||
await deployUniversalResolver( | ||||||
l1Signer, | ||||||
await RegistryContract.getAddress(), | ||||||
gatewayUrl, | ||||||
) | ||||||
}) | ||||||
|
||||||
/* | ||||||
This test will fail when it reach the gateway | ||||||
because the offchain part is not implemented yet. | ||||||
*/ | ||||||
it('Call ENS flow with viem.', async () => { | ||||||
// ENS address | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
const ensAddress = normalize('public.eth') | ||||||
// Getting Avatar from the ens address | ||||||
const client = createTestClient({ | ||||||
chain: localhost, | ||||||
mode: 'hardhat', | ||||||
transport: http('http://127.0.0.1:8545'), | ||||||
}).extend(publicActions) | ||||||
|
||||||
// console.log('ok!') | ||||||
// try { | ||||||
// await client.getEnsAvatar({ | ||||||
// name: ensAddress, | ||||||
// universalResolverAddress: | ||||||
// (await UniversalResolverContract.getAddress()) as `0x${string}`, | ||||||
// }) | ||||||
// } catch (error) { | ||||||
// const customError = error as BaseError | ||||||
// console.log(customError.message) | ||||||
// // expect(customError.message).contain('HTTP request failed') | ||||||
// } | ||||||
}) | ||||||
}) |
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. rename this file to |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,90 @@ | ||
import { ethers as eth } from 'hardhat' | ||
import { Contract, JsonRpcSigner, Wallet } from 'ethers' | ||
import { labelhash, namehash } from 'viem/ens' | ||
import { | ||
abi as abiOffchainResolver, | ||
bytecode as bytecodeOffchainResolver, | ||
} from '@blockful/contracts/out/OffchainResolver.sol/OffchainResolver.json' | ||
import { | ||
abi as abiRegistry, | ||
bytecode as bytecodeRegistry, | ||
} from '@blockful/contracts/out/ENSRegistry.sol/ENSRegistry.json' | ||
import { | ||
abi as abiUniversalResolver, | ||
bytecode as bytecodeUniversalResolver, | ||
} from '@blockful/contracts/out/UniversalResolver.sol/UniversalResolver.json' | ||
|
||
const root = eth.ZeroHash | ||
|
||
// Function to deploy offchain resolver contract | ||
export async function deployOffchainResolver( | ||
Signer: Wallet, | ||
gatewayUrl: string, | ||
signers: string, | ||
): Promise<Contract> { | ||
const ResolverContract = await new eth.ContractFactory( | ||
abiOffchainResolver, | ||
bytecodeOffchainResolver, | ||
Signer, | ||
).deploy(gatewayUrl, signers) | ||
|
||
const offchainResolver = await eth.getContractAt( | ||
abiOffchainResolver, | ||
await ResolverContract.getAddress(), | ||
) | ||
console.log('Offchain resolver: ', await ResolverContract.getAddress()) | ||
return offchainResolver | ||
} | ||
|
||
// Function to deploy registry contract | ||
export async function deployRegistry( | ||
Signer: Wallet | JsonRpcSigner, | ||
offchainResolverAddress: string, | ||
): Promise<Contract> { | ||
const RegistryContract = await new eth.ContractFactory( | ||
abiRegistry, | ||
bytecodeRegistry, | ||
Signer, | ||
).deploy() | ||
|
||
const registry = await eth.getContractAt( | ||
abiRegistry, | ||
await RegistryContract.getAddress(), | ||
) | ||
console.log('Registry: ', await RegistryContract.getAddress()) | ||
|
||
await (registry.connect(Signer) as Contract).setSubnodeRecord( | ||
root, | ||
labelhash('eth'), | ||
Signer, | ||
offchainResolverAddress, | ||
10000000, | ||
) | ||
await (registry.connect(Signer) as Contract).setSubnodeRecord( | ||
namehash('eth'), | ||
labelhash('offchain'), | ||
Signer, | ||
offchainResolverAddress, | ||
10000000, | ||
) | ||
return registry | ||
} | ||
|
||
// Function to deploy universal resolver contract | ||
export async function deployUniversalResolver( | ||
signer: Wallet | JsonRpcSigner, | ||
registry: string, | ||
gatewayUrl: string, | ||
): Promise<void> { | ||
const UniversalResolverContract = await new eth.ContractFactory( | ||
abiUniversalResolver, | ||
bytecodeUniversalResolver, | ||
signer, | ||
).deploy(registry, [gatewayUrl]) | ||
|
||
const universalResolver = await eth.getContractAt( | ||
abiUniversalResolver, | ||
await UniversalResolverContract.getAddress(), | ||
) | ||
console.log('universal resolver: ', await universalResolver.getAddress()) | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.