Skip to content

Commit a41c30d

Browse files
ceyonurJonathanOppenheimer
authored andcommitted
hello world example
1 parent 68a1670 commit a41c30d

26 files changed

+1346
-70
lines changed

.devcontainer/Dockerfile

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,3 @@ FROM mcr.microsoft.com/devcontainers/base
66

77
COPY --from=avalanchego /avalanchego/build /go/src/github.com/ava-labs/avalanchego/build
88
COPY --from=avalanche-cli /avalanche /usr/local/bin/avalanche
9-
10-
COPY --from=foundry /usr/local/bin/forge /usr/local/bin/forge
11-
COPY --from=foundry /usr/local/bin/cast /usr/local/bin/cast
12-
COPY --from=foundry /usr/local/bin/anvil /usr/local/bin/anvil
13-
COPY --from=foundry /usr/local/bin/chisel /usr/local/bin/chisel

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,6 @@ To get a comprehensive introduction to Precompile-EVM, take the Avalanche Academ
3333

3434
## How to use
3535

36-
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.
37-
3836
### 1. Generate Precompile Files
3937

4038
First, you need to create your precompile contract interface in the `contracts` directory and build the ABI. Then you can generate your precompile as such:
@@ -63,6 +61,8 @@ First, create the configuration for your subnet.
6361
avalanche blockchain create myblockchain --custom --vm $AVALANCHEGO_PLUGIN_PATH/srEXiWaHuhNyGwPUi444Tu47ZEDwxTWrbQiuD7FmgSAQ6X7Dy --genesis ./.devcontainer/genesis-example.json
6462
```
6563

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

6868
```bash

contracts/README.md

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -111,15 +111,6 @@ Subnet-EVM must activate any precompiles used in the test in the genesis:
111111
{
112112
"config": {
113113
"chainId": 43214,
114-
"homesteadBlock": 0,
115-
"eip150Block": 0,
116-
"eip155Block": 0,
117-
"eip158Block": 0,
118-
"byzantiumBlock": 0,
119-
"constantinopleBlock": 0,
120-
"petersburgBlock": 0,
121-
"istanbulBlock": 0,
122-
"muirGlacierBlock": 0,
123114
"feeConfig": {
124115
"gasLimit": 8000000,
125116
"minBaseFee": 25000000000,

contracts/contracts/.gitkeep

Whitespace-only changes.
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
//SPDX-License-Identifier: MIT
2+
pragma solidity ^0.8.0;
3+
4+
import "./interfaces/IHelloWorld.sol";
5+
6+
address constant HELLO_WORLD_ADDRESS = 0x0300000000000000000000000000000000000000;
7+
8+
// ExampleHelloWorld shows how the HelloWorld precompile can be used in a smart contract.
9+
contract ExampleHelloWorld {
10+
IHelloWorld helloWorld = IHelloWorld(HELLO_WORLD_ADDRESS);
11+
12+
function sayHello() public view returns (string memory) {
13+
return helloWorld.sayHello();
14+
}
15+
16+
function setGreeting(string calldata greeting) public {
17+
helloWorld.setGreeting(greeting);
18+
}
19+
}

contracts/contracts/interfaces/.gitkeep

Whitespace-only changes.
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
// SPDX-License-Identifier: MIT
2+
3+
pragma solidity >=0.8.0;
4+
import "@avalabs/subnet-evm-contracts/contracts/interfaces/IAllowList.sol";
5+
6+
interface IHelloWorld is IAllowList {
7+
event GreetingChanged(address indexed sender, string oldGreeting, string newGreeting);
8+
// sayHello returns the stored greeting string
9+
function sayHello() external view returns (string calldata result);
10+
11+
// setGreeting stores the greeting string
12+
function setGreeting(string calldata response) external;
13+
}

contracts/contracts/test/.gitkeep

Whitespace-only changes.
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
//SPDX-License-Identifier: MIT
2+
pragma solidity ^0.8.0;
3+
4+
import "../ExampleHelloWorld.sol";
5+
import "../interfaces/IHelloWorld.sol";
6+
import "@avalabs/subnet-evm-contracts/contracts/test/AllowListTest.sol";
7+
8+
contract ExampleHelloWorldTest is AllowListTest {
9+
IHelloWorld helloWorld = IHelloWorld(HELLO_WORLD_ADDRESS);
10+
11+
function step_getDefaultHelloWorld() public {
12+
ExampleHelloWorld example = new ExampleHelloWorld();
13+
address exampleAddress = address(example);
14+
15+
assertRole(helloWorld.readAllowList(exampleAddress), AllowList.Role.None);
16+
assertEq(example.sayHello(), "Hello World!");
17+
}
18+
19+
function step_doesNotSetGreetingBeforeEnabled() public {
20+
ExampleHelloWorld example = new ExampleHelloWorld();
21+
address exampleAddress = address(example);
22+
23+
assertRole(helloWorld.readAllowList(exampleAddress), AllowList.Role.None);
24+
25+
try example.setGreeting("testing") {
26+
assertTrue(false, "setGreeting should fail");
27+
} catch {} // TODO should match on an error to make sure that this is failing in the way that's expected
28+
}
29+
30+
function step_setAndGetGreeting() public {
31+
ExampleHelloWorld example = new ExampleHelloWorld();
32+
address exampleAddress = address(example);
33+
34+
assertRole(helloWorld.readAllowList(exampleAddress), AllowList.Role.None);
35+
helloWorld.setEnabled(exampleAddress);
36+
assertRole(helloWorld.readAllowList(exampleAddress), AllowList.Role.Enabled);
37+
38+
string memory greeting = "testgreeting";
39+
example.setGreeting(greeting);
40+
assertEq(example.sayHello(), greeting);
41+
}
42+
}

contracts/package-lock.json

Lines changed: 85 additions & 45 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)