Allow enums to be used as function parameters
This commit is contained in:
parent
9ef6c08072
commit
00b511cc9b
|
@ -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"
|
||||
|
|
|
@ -2,6 +2,7 @@ import ./testJsonRpcProvider
|
|||
import ./testJsonRpcSigner
|
||||
import ./testContracts
|
||||
import ./testReturns
|
||||
import ./testEnums
|
||||
import ./testEvents
|
||||
|
||||
{.warning[UnusedImport]:off.}
|
||||
|
|
|
@ -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
|
|
@ -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;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,6 @@
|
|||
module.exports = async ({ deployments, getNamedAccounts }) => {
|
||||
const { deployer } = await getNamedAccounts();
|
||||
await deployments.deploy("TestEnums", { from: deployer });
|
||||
};
|
||||
|
||||
module.exports.tags = ["TestEnums"];
|
Loading…
Reference in New Issue