Skip to content

Commit

Permalink
fix: Hardhat tests running on Solo (#22)
Browse files Browse the repository at this point in the history
* first commit

* first commit

* some tests fixed

* more tests

* more tests fixed

* added correct chainId for solo

* fixed more tests

* removed unneccessary await

* fix: leaving the code as it was

* fix: changed entrypoint contract

* more tests fixed

* fix: changed entrypoint contract

* fix: small change

* fix: getting chainid from a single place

* more tests fixed

* comment amended

* more changes

* more tests fixed

* more tests fixed

* ci

* test

* renamed package scripts for tests

* renamed package scripts for tests

* removed unused test file since the test is duplicated

* fixed helpers test

* small change

* using entrypoint to fund vtho

* test cleanup

* test cleanup

* fixed another test

* all tests passing

* fixed some problems

* fixed last test

* shards config

* shards config

* shards config

* shards config

* shards config

* added all util files to utils folder

* 3rd shard

* 3rd shard

* 3rd shard

* 3rd shard

* 3rd shard

* removed only

* checking for failers

* fail-fast added

* fixed one more test

* fixed the other test

* running pipeline only on PRs

* fixed the other test

* added network support

* readme updated

* readme updated

* readme updated

* tests reviewed

* adding chainId depending on the network

* removed from block since it runs from solo and sometimes the block goes before the one in the receipt

* readme updated

* file renamed

* readme updated

* contributing renamed

* removed base gasfee

* removed base gasfee

* allowance checked already performed

* test fixed

* removed identation
  • Loading branch information
freemanzMrojo authored Aug 26, 2024
1 parent f222461 commit 7d50d00
Show file tree
Hide file tree
Showing 29 changed files with 1,029 additions and 1,043 deletions.
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

0 comments on commit 7d50d00

Please sign in to comment.