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

fix: Hardhat tests running on Solo #22

Merged
merged 67 commits into from
Aug 26, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
67 commits
Select commit Hold shift + click to select a range
7323710
first commit
freemanzMrojo Aug 21, 2024
a5e58e3
first commit
freemanzMrojo Aug 21, 2024
a720ea0
some tests fixed
freemanzMrojo Aug 21, 2024
c3e6178
more tests
freemanzMrojo Aug 21, 2024
fc69b65
more tests fixed
freemanzMrojo Aug 21, 2024
da009f8
added correct chainId for solo
freemanzMrojo Aug 22, 2024
a5ef094
fixed more tests
freemanzMrojo Aug 22, 2024
7925416
removed unneccessary await
freemanzMrojo Aug 22, 2024
1e6f80c
fix: leaving the code as it was
freemanzMrojo Aug 23, 2024
f9ccc55
fix: changed entrypoint contract
freemanzMrojo Aug 23, 2024
c3ece2f
more tests fixed
freemanzMrojo Aug 23, 2024
8132c9b
fix: changed entrypoint contract
freemanzMrojo Aug 23, 2024
76076fa
fix: small change
freemanzMrojo Aug 23, 2024
3cfb581
fix: getting chainid from a single place
freemanzMrojo Aug 23, 2024
e7e2d41
more tests fixed
freemanzMrojo Aug 23, 2024
72fb0e6
comment amended
freemanzMrojo Aug 23, 2024
3686b32
more changes
freemanzMrojo Aug 23, 2024
48cf32c
more tests fixed
freemanzMrojo Aug 23, 2024
fb2046a
more tests fixed
freemanzMrojo Aug 23, 2024
dca753b
ci
freemanzMrojo Aug 23, 2024
7621b0e
test
freemanzMrojo Aug 23, 2024
147cef5
renamed package scripts for tests
freemanzMrojo Aug 23, 2024
2153e97
renamed package scripts for tests
freemanzMrojo Aug 23, 2024
a857ddb
removed unused test file since the test is duplicated
freemanzMrojo Aug 23, 2024
d0ceed0
fixed helpers test
freemanzMrojo Aug 23, 2024
f8c88c2
small change
freemanzMrojo Aug 23, 2024
d86df48
using entrypoint to fund vtho
freemanzMrojo Aug 23, 2024
6fdb1cc
test cleanup
freemanzMrojo Aug 23, 2024
33f9c76
test cleanup
freemanzMrojo Aug 23, 2024
4720b9f
fixed another test
freemanzMrojo Aug 25, 2024
03d8e36
all tests passing
freemanzMrojo Aug 25, 2024
79190d7
fixed some problems
freemanzMrojo Aug 25, 2024
ca4fbe4
fixed last test
freemanzMrojo Aug 25, 2024
07bf4ee
shards config
freemanzMrojo Aug 25, 2024
190c51c
shards config
freemanzMrojo Aug 25, 2024
5f67df7
shards config
freemanzMrojo Aug 25, 2024
1a94ced
shards config
freemanzMrojo Aug 25, 2024
bd17c76
shards config
freemanzMrojo Aug 25, 2024
a3f689d
added all util files to utils folder
freemanzMrojo Aug 25, 2024
8df32d7
3rd shard
freemanzMrojo Aug 25, 2024
43cfec8
3rd shard
freemanzMrojo Aug 25, 2024
fdc7ac7
3rd shard
freemanzMrojo Aug 25, 2024
e955842
3rd shard
freemanzMrojo Aug 25, 2024
93bb595
3rd shard
freemanzMrojo Aug 25, 2024
d595346
removed only
freemanzMrojo Aug 26, 2024
da083bd
checking for failers
freemanzMrojo Aug 26, 2024
c7d3725
fail-fast added
freemanzMrojo Aug 26, 2024
c5692d1
fixed one more test
freemanzMrojo Aug 26, 2024
e21b5c9
fixed the other test
freemanzMrojo Aug 26, 2024
0cebbb9
running pipeline only on PRs
freemanzMrojo Aug 26, 2024
a421c09
fixed the other test
freemanzMrojo Aug 26, 2024
6b159b2
added network support
freemanzMrojo Aug 26, 2024
a493ebf
readme updated
freemanzMrojo Aug 26, 2024
e7c663c
readme updated
freemanzMrojo Aug 26, 2024
cd8e9cd
readme updated
freemanzMrojo Aug 26, 2024
5175d58
tests reviewed
freemanzMrojo Aug 26, 2024
1ea8d5b
adding chainId depending on the network
freemanzMrojo Aug 26, 2024
a1acb51
removed from block since it runs from solo and sometimes the block go…
freemanzMrojo Aug 26, 2024
117c583
readme updated
freemanzMrojo Aug 26, 2024
13d2d65
file renamed
freemanzMrojo Aug 26, 2024
bf2e0dc
readme updated
freemanzMrojo Aug 26, 2024
ac46542
contributing renamed
freemanzMrojo Aug 26, 2024
79a0082
removed base gasfee
freemanzMrojo Aug 26, 2024
28bce97
removed base gasfee
freemanzMrojo Aug 26, 2024
7a099fd
allowance checked already performed
freemanzMrojo Aug 26, 2024
421e472
test fixed
freemanzMrojo Aug 26, 2024
a8721aa
removed identation
freemanzMrojo Aug 26, 2024
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
88 changes: 0 additions & 88 deletions .github/workflows/build.yml

This file was deleted.

17 changes: 17 additions & 0 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
name: Account Abstraction workflow

on:
workflow_dispatch:
pull_request:
branches:
- vechain

jobs:
call-workflow-hardhat-tests:
uses: ./.github/workflows/test-contracts.yml
with:
shard-matrix: "{ \"shard\": [1,2,3] }"
secrets: inherit



47 changes: 47 additions & 0 deletions .github/workflows/test-contracts.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
name: Account abstraction contract tests

on:
workflow_call:
inputs:
shard-matrix:
required: true
type: string

jobs:
run-tests-and-build-report:
name: Test Smart Contracts with Hardhat
runs-on: ubuntu-latest
permissions:
actions: read
contents: read
security-events: write
packages: read
strategy:
fail-fast: false
matrix: ${{ fromJSON(inputs.shard-matrix) }}

steps:
- name: Checkout repository
uses: actions/checkout@v4
with:
fetch-depth: 0

- name: Use Node v20
uses: actions/setup-node@v4
with:
node-version: 20
cache: 'yarn'
registry-url: 'https://npm.pkg.github.com'
always-auth: true
scope: '@vechain'
env:
NODE_AUTH_TOKEN: ${{ secrets.GITHUB_TOKEN }}

- name: Install dependencies
run: yarn install

- name: Smart contract tests
run: yarn test:shard${{ matrix.shard }}:compose:v2



File renamed without changes.
65 changes: 38 additions & 27 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,33 +1,48 @@
# VeChain Account Abstraction contracts

Implementation of contracts for [ERC-4337](https://eips.ethereum.org/EIPS/eip-4337) account abstraction via alternative mempool.

This project is based on [eth-infinitism v0.6.0 implementation](https://github.com/eth-infinitism/account-abstraction/tree/abff2aca61a8f0934e533d0d352978055fddbd96).

![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)

# Vechain Specific Changes
The changes mainly concern VTHO support, as the gas unit that is refunded.
## VeChain Specific Changes
The changes mainly concern VTHO support, as the gas unit that is prefunded.

# Test
## Test using Thor Solo

## Deploy all on Solo
The tests run using Docker Compose to bring up a Thor Solo instance. You should also install all dependencies first by running `yarn install`.

Make sure your `hardhat.config.ts` has the following line:
When using Docker Compose V1, please run the script:

```ts
vechain: {
url: VECHAIN_URL_SOLO
}
```bash
yarn test:compose:v1
```

If you have Docker Compose V2, please run this instead:

```bash
yarn test:compose:v2
```

If you need to find out first which one is your version, please execute (V1 would be the below)

And then deploy all contracts (entryPoint included)
```bash
yarn hardhat test --network vechain test/deploy-contracts.test.ts
➜ docker-compose -v
docker-compose version 1.29.2, build 5becea4c
```

## Deploy EntryPoint on Testnet
The test files are placed in separate folders (`shard1`, `shard2`...) so we can parallelise the execution in the pipelines.

## Test on networks

**DISCLAIMER**: There are over a hundred tests in this repository. Further adjustments might be required in this case (for instance, make sure that the sender account is well-funded).

### Deploy contracts on Testnet
To deploy on testnet modify the `hardhat.config.ts` with the following

```ts
vechain: {
vechain_testnet: {
url: VECHAIN_URL_TESTNET,
accounts: {
mnemonic: "your testnet mnemonic goes here"
Expand All @@ -37,14 +52,14 @@ vechain: {

And run the deployment script
```bash
yarn hardhat test --network vechain test/deploy-entrypoint.test.ts
yarn hardhat test --network vechain_testnet shard1/deploy-contracts.test.ts
```

## Deploy EntryPoint on Mainnet
### Deploy contracts on Mainnet
To deploy on testnet modify the `hardhat.config.ts` with the following

```ts
vechain: {
vechain_mainnet: {
url: VECHAIN_URL_MAINNET,
accounts: {
mnemonic: "your mainnet mnemonic goes here"
Expand All @@ -54,26 +69,22 @@ vechain: {

And run the deployment script
```bash
yarn hardhat test --network vechain test/deploy-entrypoint.test.ts
yarn hardhat test --network vechain_mainnet shard1/deploy-contracts.test.ts
```

### Run tests on a network

Update [./test/config.ts](./test/config.ts) with the addresses of the deployed contracts and
Update [./test/utils/config.ts](./test/utils/config.ts) with the addresses of the deployed contracts and then for testnet:

Run entryPoint tests:
```bash
yarn hardhat test test/entrypoint.test.ts --network vechain
yarn test:testnet
```

Run paymaster tests:
And for mainnet:
```bash
yarn hardhat test test/paymaster.test.ts --network vechain
yarn test:mainnet
```

Run simple wallet tests:
```bash
yarn hardhat test test/simple-wallet.test.ts --network vechain
```

# Resources
## Resources
- [Vitalik's post on account abstraction without Ethereum protocol changes](https://medium.com/infinitism/erc-4337-account-abstraction-without-ethereum-protocol-changes-d75c9d94dc4a)
4 changes: 2 additions & 2 deletions contracts/core/EntryPoint.sol
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,8 @@ contract EntryPoint is IEntryPoint, StakeManager, NonceManager, ReentrancyGuard

UserOpInfo[] memory opInfos = new UserOpInfo[](totalOps);

emit BeforeExecution();

uint256 opIndex = 0;
for (uint256 a = 0; a < opasLen; a++) {
UserOpsPerAggregator calldata opa = opsPerAggregator[a];
Expand All @@ -164,8 +166,6 @@ contract EntryPoint is IEntryPoint, StakeManager, NonceManager, ReentrancyGuard
}
}

emit BeforeExecution();

uint256 collected = 0;
opIndex = 0;
for (uint256 a = 0; a < opasLen; a++) {
Expand Down
19 changes: 13 additions & 6 deletions contracts/samples/SimpleAccount.sol
Original file line number Diff line number Diff line change
Expand Up @@ -43,13 +43,13 @@ contract SimpleAccount is BaseAccount, TokenCallbackHandler, UUPSUpgradeable, In
function deposit(uint256 amount) public {
_onlyOwner();
require(VTHO_TOKEN_CONTRACT.approve(address(_entryPoint), amount), "Aproval to EntryPoint Failed");
_entryPoint.depositAmountTo(address(this), amount);
entryPoint().depositAmountTo(address(this), amount);
}

function withdrawAll() public {
_onlyOwner();
IStakeManager.DepositInfo memory depositInfo = _entryPoint.getDepositInfo(address(this));
_entryPoint.withdrawTo(address(this), depositInfo.deposit);
entryPoint().withdrawTo(address(this), depositInfo.deposit);
}

// solhint-disable-next-line no-empty-blocks
Expand Down Expand Up @@ -121,18 +121,25 @@ contract SimpleAccount is BaseAccount, TokenCallbackHandler, UUPSUpgradeable, In
}
}

function _authorizeUpgrade(address newImplementation) internal view override {
(newImplementation);
_onlyOwner();
/**
* check current account deposit in the entryPoint
*/
function getDeposit() public view returns (uint256) {
return entryPoint().balanceOf(address(this));
}

/**
/**
* withdraw value from the account's deposit
* @param withdrawAddress target to send to
* @param amount to withdraw
*/
function withdrawDepositTo(address payable withdrawAddress, uint256 amount) public onlyOwner {
entryPoint().withdrawTo(withdrawAddress, amount);
}

function _authorizeUpgrade(address newImplementation) internal view override {
(newImplementation);
_onlyOwner();
}
}

22 changes: 14 additions & 8 deletions hardhat.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,24 +5,19 @@ import 'hardhat-deploy'
import '@nomiclabs/hardhat-etherscan'

import '@nomiclabs/hardhat-truffle5'
import { VECHAIN_URL_SOLO } from '@vechain/hardhat-vechain'
import { VECHAIN_URL_MAINNET, VECHAIN_URL_SOLO, VECHAIN_URL_TESTNET } from '@vechain/hardhat-vechain'
import '@vechain/hardhat-ethers'
import '@vechain/hardhat-web3'

const optimizedComilerSettings = {
version: '0.8.17',
settings: {
optimizer: { enabled: true, runs: 1000000 }
}
}
const shardNumber = process.env.shard

// You need to export an object to set up your config
// Go to https://hardhat.org/config/ to learn more

const config: HardhatUserConfig = {
solidity: {
compilers: [{
version: '0.8.15',
version: '0.8.20',
settings: {
optimizer: { enabled: true, runs: 1000000 }
}
Expand All @@ -31,8 +26,19 @@ const config: HardhatUserConfig = {
networks: {
vechain: {
url: VECHAIN_URL_SOLO
},
vechain_testnet: {
url: VECHAIN_URL_TESTNET
},
vechain_mainnet: {
url: VECHAIN_URL_MAINNET
}
},
paths: {
tests: shardNumber !== undefined && shardNumber !== null && shardNumber !== ''
? `./test/shard${shardNumber}`
: './test'
},
mocha: {
timeout: 180000
}
Expand Down
Loading