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

add hello world example #12

Draft
wants to merge 19 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
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
5 changes: 0 additions & 5 deletions .devcontainer/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,3 @@ FROM mcr.microsoft.com/devcontainers/base

COPY --from=avalanchego /avalanchego/build /go/src/github.com/ava-labs/avalanchego/build
COPY --from=avalanche-cli /avalanche /usr/local/bin/avalanche

COPY --from=foundry /usr/local/bin/forge /usr/local/bin/forge
COPY --from=foundry /usr/local/bin/cast /usr/local/bin/cast
COPY --from=foundry /usr/local/bin/anvil /usr/local/bin/anvil
COPY --from=foundry /usr/local/bin/chisel /usr/local/bin/chisel
2 changes: 1 addition & 1 deletion .devcontainer/devcontainer.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
"build": {
"dockerfile": "Dockerfile",
"args": {
"AVALANCHEGO_VERSION": "v1.11.13"
"AVALANCHEGO_VERSION": "v1.12.2"
}
},
"runArgs": ["--network=host"],
Expand Down
24 changes: 24 additions & 0 deletions .github/workflows/sync.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
name: Sync
on:
push:
branches:
- main

jobs:
sync-branches:
runs-on: ubuntu-latest
name: Syncing branches
steps:
- name: Checkout
uses: actions/checkout@v2
- name: Set up Node
uses: actions/setup-node@v1
with:
node-version: 12
- name: Opening pull request
id: pull
uses: tretuna/sync-branches@1.4.0
with:
GITHUB_TOKEN: ${{secrets.GITHUB_TOKEN}}
FROM_BRANCH: "main"
TO_BRANCH: "develop"
2 changes: 1 addition & 1 deletion .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ on:
pull_request:

env:
min_go_version: "~1.21.12"
min_go_version: "~1.22.8"

jobs:
lint_test:
Expand Down
9 changes: 5 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,9 @@ In order to run the Dev Container locally:

To get a comprehensive introduction to Precompile-EVM, take the Avalanche Academy course on [Customizing the EVM](https://academy.avax.com/course/customizing-evm).

## How to use
## Hello World Example

There is an example branch [hello-world-example](https://github.com/ava-labs/precompile-evm/tree/hello-world-example) in this repository. You can check the example branch to see how to register precompiles and test them.
### 1. Clone the Repo

### 1. Generate Precompile Files

Expand Down Expand Up @@ -61,7 +61,7 @@ First, create the configuration for your subnet.
avalanche blockchain create myblockchain --custom --vm $AVALANCHEGO_PLUGIN_PATH/srEXiWaHuhNyGwPUi444Tu47ZEDwxTWrbQiuD7FmgSAQ6X7Dy --genesis ./.devcontainer/genesis-example.json
```

Next, launch the Subnet with your custom VM:
Confirm that the new `holamundo/` directory has the appropriate files.

```bash
avalanche blockchain deploy myblockchain
Expand All @@ -83,5 +83,6 @@ In order to upgrade the Subnet-EVM version, you need to change the version in `g
[v0.2.2] AvalancheGo@v1.11.3-v1.11.9 (Protocol Version: 35)
[v0.2.3] AvalancheGo@v1.11.3-v1.11.9 (Protocol Version: 35)
[v0.2.4] AvalancheGo@v1.11.11-v1.11.12 (Protocol Version: 37)
[v0.2.5] AvalancheGo@v1.11.13/v1.12.0-fuji (Protocol Version: 38)
[v0.2.5] AvalancheGo@v1.11.13-v1.12.1 (Protocol Version: 38)
[v0.3.0] AvalancheGo@v1.12.2 (Protocol Version: 39)
```
12 changes: 2 additions & 10 deletions compatibility.json
Original file line number Diff line number Diff line change
@@ -1,19 +1,11 @@
{
"rpcChainVMProtocolVersion": {
"v0.3.0": 39,
"v0.2.5": 38,
"v0.2.4": 37,
"v0.2.3": 35,
"v0.2.2": 35,
"v0.2.1": 35,
"v0.2.0": 33,
"v0.1.8": 31,
"v0.1.7": 30,
"v0.1.6": 30,
"v0.1.5": 29,
"v0.1.4": 28,
"v0.1.3": 28,
"v0.1.2": 27,
"v0.1.1": 26,
"v0.1.0": 26
"v0.2.0": 33
}
}
9 changes: 0 additions & 9 deletions contracts/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -111,15 +111,6 @@ Subnet-EVM must activate any precompiles used in the test in the genesis:
{
"config": {
"chainId": 43214,
"homesteadBlock": 0,
"eip150Block": 0,
"eip155Block": 0,
"eip158Block": 0,
"byzantiumBlock": 0,
"constantinopleBlock": 0,
"petersburgBlock": 0,
"istanbulBlock": 0,
"muirGlacierBlock": 0,
"feeConfig": {
"gasLimit": 8000000,
"minBaseFee": 25000000000,
Expand Down
Empty file removed contracts/contracts/.gitkeep
Empty file.
19 changes: 19 additions & 0 deletions contracts/contracts/ExampleHelloWorld.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
//SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;

import "./interfaces/IHelloWorld.sol";

address constant HELLO_WORLD_ADDRESS = 0x0300000000000000000000000000000000000000;

// ExampleHelloWorld shows how the HelloWorld precompile can be used in a smart contract.
contract ExampleHelloWorld {
IHelloWorld helloWorld = IHelloWorld(HELLO_WORLD_ADDRESS);

function sayHello() public view returns (string memory) {
return helloWorld.sayHello();
}

function setGreeting(string calldata greeting) public {
helloWorld.setGreeting(greeting);
}
}
Empty file.
13 changes: 13 additions & 0 deletions contracts/contracts/interfaces/IHelloWorld.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
// SPDX-License-Identifier: MIT

pragma solidity >=0.8.0;
import "@avalabs/subnet-evm-contracts/contracts/interfaces/IAllowList.sol";

interface IHelloWorld is IAllowList {
event GreetingChanged(address indexed sender, string oldGreeting, string newGreeting);
// sayHello returns the stored greeting string
function sayHello() external view returns (string calldata result);

// setGreeting stores the greeting string
function setGreeting(string calldata response) external;
}
Empty file removed contracts/contracts/test/.gitkeep
Empty file.
42 changes: 42 additions & 0 deletions contracts/contracts/test/ExampleHelloWorldTest.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
//SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;

import "../ExampleHelloWorld.sol";
import "../interfaces/IHelloWorld.sol";
import "@avalabs/subnet-evm-contracts/contracts/test/AllowListTest.sol";

contract ExampleHelloWorldTest is AllowListTest {
IHelloWorld helloWorld = IHelloWorld(HELLO_WORLD_ADDRESS);

function step_getDefaultHelloWorld() public {
ExampleHelloWorld example = new ExampleHelloWorld();
address exampleAddress = address(example);

assertRole(helloWorld.readAllowList(exampleAddress), AllowList.Role.None);
assertEq(example.sayHello(), "Hello World!");
}

function step_doesNotSetGreetingBeforeEnabled() public {
ExampleHelloWorld example = new ExampleHelloWorld();
address exampleAddress = address(example);

assertRole(helloWorld.readAllowList(exampleAddress), AllowList.Role.None);

try example.setGreeting("testing") {
assertTrue(false, "setGreeting should fail");
} catch {} // TODO should match on an error to make sure that this is failing in the way that's expected
}

function step_setAndGetGreeting() public {
ExampleHelloWorld example = new ExampleHelloWorld();
address exampleAddress = address(example);

assertRole(helloWorld.readAllowList(exampleAddress), AllowList.Role.None);
helloWorld.setEnabled(exampleAddress);
assertRole(helloWorld.readAllowList(exampleAddress), AllowList.Role.Enabled);

string memory greeting = "testgreeting";
example.setGreeting(greeting);
assertEq(example.sayHello(), greeting);
}
}
Loading
Loading