-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
30 changed files
with
1,171 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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/[email protected] | ||
with: | ||
GITHUB_TOKEN: ${{secrets.GITHUB_TOKEN}} | ||
FROM_BRANCH: "main" | ||
TO_BRANCH: "develop" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
[{"inputs":[{"internalType":"address","name":"addr","type":"address"}],"name":"readAllowList","outputs":[{"internalType":"uint256","name":"role","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"addr","type":"address"}],"name":"setAdmin","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"addr","type":"address"}],"name":"setEnabled","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"addr","type":"address"}],"name":"setNone","outputs":[],"stateMutability":"nonpayable","type":"function"}] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
[{"inputs":[{"internalType":"address","name":"addr","type":"address"}],"name":"readAllowList","outputs":[{"internalType":"uint256","name":"role","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"sayHello","outputs":[{"internalType":"string","name":"result","type":"string"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"addr","type":"address"}],"name":"setAdmin","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"addr","type":"address"}],"name":"setEnabled","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"string","name":"response","type":"string"}],"name":"setGreeting","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"addr","type":"address"}],"name":"setNone","outputs":[],"stateMutability":"nonpayable","type":"function"}] |
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
// SPDX-License-Identifier: MIT | ||
|
||
pragma solidity >=0.8.0; | ||
import "@avalabs/subnet-evm-contracts/contracts/interfaces/IAllowList.sol"; | ||
|
||
interface IHelloWorld is IAllowList { | ||
// 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.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
import { | ||
Contract, | ||
ContractFactory | ||
} from "ethers" | ||
import { ethers } from "hardhat" | ||
|
||
const main = async (): Promise<any> => { | ||
const contractFactory: ContractFactory = await ethers.getContractFactory("ExampleHelloWorld") | ||
const contract: Contract = await contractFactory.deploy() | ||
|
||
await contract.deployed() | ||
console.log(`Contract deployed to: ${contract.address}`) | ||
} | ||
|
||
main() | ||
.then(() => process.exit(0)) | ||
.catch(error => { | ||
console.error(error) | ||
process.exit(1) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
// (c) 2019-2022, Ava Labs, Inc. All rights reserved. | ||
// See the file LICENSE for licensing terms. | ||
|
||
import { ethers } from "hardhat" | ||
import { test } from "@avalabs/subnet-evm-contracts" | ||
|
||
// make sure this is always an admin for hello world precompile | ||
const ADMIN_ADDRESS = "0x8db97C7cEcE249c2b98bDC0226Cc4C2A57BF52FC" | ||
const HELLO_WORLD_ADDRESS = "0x0300000000000000000000000000000000000000" | ||
|
||
describe("ExampleHelloWorldTest", function () { | ||
this.timeout("30s") | ||
|
||
beforeEach('Setup DS-Test contract', async function () { | ||
const signer = await ethers.getSigner(ADMIN_ADDRESS) | ||
const helloWorldPromise = ethers.getContractAt("IHelloWorld", HELLO_WORLD_ADDRESS, signer) | ||
|
||
return ethers.getContractFactory("ExampleHelloWorldTest", { signer }) | ||
.then(factory => factory.deploy()) | ||
.then(contract => { | ||
this.testContract = contract | ||
return contract.deployed().then(() => contract) | ||
}) | ||
.then(() => Promise.all([helloWorldPromise])) | ||
.then(([helloWorld]) => helloWorld.setAdmin(this.testContract.address)) | ||
.then(tx => tx.wait()) | ||
}) | ||
|
||
test("should gets default hello world", ["step_getDefaultHelloWorld"]) | ||
|
||
test("should not set greeting before enabled", "step_doesNotSetGreetingBeforeEnabled") | ||
|
||
test("should set and get greeting with enabled account", "step_setAndGetGreeting") | ||
}); |
Oops, something went wrong.