Allow enums to be used as function parameters

This commit is contained in:
Mark Spanbroek 2022-06-15 09:57:43 +02:00 committed by markspanbroek
parent 9ef6c08072
commit 00b511cc9b
5 changed files with 48 additions and 1 deletions

View File

@ -4,7 +4,7 @@ description = "library for interacting with Ethereum"
license = "MIT"
requires "chronos >= 3.0.0 & < 4.0.0"
requires "contractabi >= 0.4.4 & < 0.5.0"
requires "contractabi >= 0.4.5 & < 0.5.0"
requires "questionable >= 0.10.2 & < 0.11.0"
requires "upraises >= 0.1.0 & < 0.2.0"
requires "json_rpc"

View File

@ -2,6 +2,7 @@ import ./testJsonRpcProvider
import ./testJsonRpcSigner
import ./testContracts
import ./testReturns
import ./testEnums
import ./testEvents
{.warning[UnusedImport]:off.}

30
testmodule/testEnums.nim Normal file
View File

@ -0,0 +1,30 @@
import pkg/asynctest
import pkg/ethers
import ./hardhat
type
TestEnums = ref object of Contract
SomeEnum = enum
One
Two
suite "Contract enum parameters and return values":
var contract: TestEnums
var provider: JsonRpcProvider
var snapshot: JsonNode
setup:
provider = JsonRpcProvider.new("ws://localhost:8545")
snapshot = await provider.send("evm_snapshot")
let deployment = readDeployment()
contract = TestEnums.new(!deployment.address(TestEnums), provider)
teardown:
discard await provider.send("evm_revert", @[snapshot])
test "handles enum parameter and return value":
proc returnValue(contract: TestEnums,
value: SomeEnum): SomeEnum {.contract, pure.}
check (await contract.returnValue(SomeEnum.One)) == SomeEnum.One
check (await contract.returnValue(SomeEnum.Two)) == SomeEnum.Two

View File

@ -0,0 +1,10 @@
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;
contract TestEnums {
enum SomeEnum { One, Two }
function returnValue(SomeEnum value) external pure returns (SomeEnum) {
return value;
}
}

View File

@ -0,0 +1,6 @@
module.exports = async ({ deployments, getNamedAccounts }) => {
const { deployer } = await getNamedAccounts();
await deployments.deploy("TestEnums", { from: deployer });
};
module.exports.tags = ["TestEnums"];