solidity enum VotingSystem { MEMBERSHIP, NETWORKGOVERNANCETOKEN, ANY_TOKEN } struct…
- User
solidity enum VotingSystem { MEMBERSHIP, NETWORK_GOVERNANCE_TOKEN, ANY_TOKEN } struct VotingToken { uint256 chainId; address token; address balanceType; // voting power strategy // address 1 // address 2 }
struct VotingSystemTokenCheckpoint { uint256 fromBlock; VotingToken[] votingTokens; } struct VotingSystemLayout { VotingSystemTokenCheckpoint[] checkpoints; mapping(uint256 /* current chain blockNumber */ => mapping(uint256 /* chainId */ => uint256)) otherChainBlockNumbers; }function setVotingSystem( VotingSystem vs, VotingToken[] memory votingTokens ) external { SettingsStorage.justSetUint256Setting(VOTING_SYSTEM_SETTING_KEY, uint256(vs)); if (vs == VotingSystem.MEMBERSHIP) { VotingToken[] memory emptyArray = new VotingToken; _setVotingTokens(emptyArray); emit VotingSystemTokensUpdated(emptyArray); } else { IVotingPowerTypeRegistry votingPowerTypeRegistry = IVotingPowerTypeRegistry( SettingsStorage.getAddressSetting(VOTING_POWER_TYPE_REGISTRY_ADDRESS) ); unchecked { for (uint256 i = 0; i < votingTokens.length; i++) { require( votingPowerTypeRegistry.isVotingPowerType(votingTokens[i].balanceType), "WRONG_BALANCE_TYPE_ADDRESS" ); if (vs == VotingSystem.NETWORK_GOVERNANCE_TOKEN) { require(votingTokens[i].chainId == block.chainid, "WRONG_CHAIN_ID"); } } } _setVotingTokens(votingTokens); emit VotingSystemTokensUpdated(votingTokens); } } write python test for setVotingSystem
- Assistant
I can provide you with a Python test framework using the
unittestmodule to test thesetVotingSystemfunction. Here's an example:import unittest class VotingSystemTestCase(unittest.TestCase): def setUp(self): # Set up any initial configurations or dependencies def test_set_voting_system_membership(self): # Test the scenario when the VotingSystem is MEMBERSHIP # Arrange vs = VotingSystem.MEMBERSHIP votingTokens = [] # Act self.contract.setVotingSystem(vs, votingTokens) # Assert self.assertEqual(self.contract.currentVotingSystem, vs) self.assertEqual(self.contract.votingTokens, []) self.assertEqual(self.contract.votingSystemTokensUpdatedEventEmitted, True) def test_set_voting_system_network_governance_token(self): # Test the scenario when the VotingSystem is NETWORK_GOVERNANCE_TOKEN # Arrange vs = VotingSystem.NETWORK_GOVERNANCE_TOKEN votingTokens = [VotingToken(1, "0x123...", "0x456...")] # Act self.contract.setVotingSystem(vs, votingTokens) # Assert self.assertEqual(self.contract.currentVotingSystem, vs) self.assertEqual(self.contract.votingTokens, votingTokens) self.assertEqual(self.contract.votingSystemTokensUpdatedEventEmitted, True) def test_set_voting_system_any_token(self): # Test the scenario when the VotingSystem is ANY_TOKEN # Arrange vs = VotingSystem.ANY_TOKEN votingTokens = [VotingToken(1, "0x123...", "0x456..."), VotingToken(2, "0x789...", "0xabc...")] # Act self.contract.setVotingSystem(vs, votingTokens) # Assert self.assertEqual(self.contract.currentVotingSystem, vs) self.assertEqual(self.contract.votingTokens, votingTokens) self.assertEqual(self.contract.votingSystemTokensUpdatedEventEmitted, True) if __name__ == '__main__': unittest.main() - User
rewrite for brownie framework with pytest
- Assistant
Certainly! Here's an example of how you can write the test for the
setVotingSystemfunction using the Brownie framework with pytest:import pytest from brownie import VotingSystem, VotingToken def test_set_voting_system_membership(contract): # Test the scenario when the VotingSystem is MEMBERSHIP # Arrange vs = VotingSystem.MEMBERSHIP votingTokens = [] # Act contract.setVotingSystem(vs, votingTokens) # Assert assert contract.currentVotingSystem() == vs assert contract.votingTokens() == [] assert contract.votingSystemTokensUpdatedEventEmitted() == True def test_set_voting_system_network_governance_token(contract): # Test the scenario when the VotingSystem is NETWORK_GOVERNANCE_TOKEN # Arrange vs = VotingSystem.NETWORK_GOVERNANCE_TOKEN votingTokens = [(1, "0x123...", "0x456...")] # Act contract.setVotingSystem(vs, votingTokens) # Assert assert contract.currentVotingSystem() == vs assert contract.votingTokens() == votingTokens assert contract.votingSystemTokensUpdatedEventEmitted() == True def test_set_voting_system_any_token(contract): # Test the scenario when the VotingSystem is ANY_TOKEN # Arrange vs = VotingSystem.ANY_TOKEN votingTokens = [(1, "0x123...", "0x456..."), (2, "0x789...", "0xabc...")] # Act contract.setVotingSystem(vs, votingTokens) # Assert assert contract.currentVotingSystem() == vs assert contract.votingTokens() == votingTokens assert contract.votingSystemTokensUpdatedEventEmitted() == True - User
eth_abi.exceptions.NoEntriesFound: No matching entries for 'tuple' in encoder registry
- Assistant
Apologies for the confusion. It seems that you're encountering an error related to ABI encoding using the
eth_abilibrary. In this case, it appears that the library is not recognizing thetupledata type in the ABI.To resolve this issue, you can manually encode the data for the
VotingTokenstruct using theeth_abi.encode_abifunction. Here's an updated version of the test code with the necessary modifications:
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.