evm-tokenvote

Voting machine using ERC20 tokens as votes.
Log | Files | Refs | README

commit d5660ad9863fedccb2febc001dbeeb99a8920d8b
parent 3d76eb1383eb99a778d648dcc32119f690ff5ec5
Author: lash <dev@holbrook.no>
Date:   Sat,  6 May 2023 14:09:37 +0100

Add option vote tests, interface

Diffstat:
Mpython/evm_tokenvote/data/Voter.bin | 4++--
Mpython/evm_tokenvote/data/Voter.json | 2+-
Mpython/evm_tokenvote/data/Voter.metadata.json | 2+-
Mpython/evm_tokenvote/unittest/base.py | 2++
Mpython/evm_tokenvote/voter.py | 75++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++---
Apython/tests/test_option.py | 201+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Msolidity/Voter.sol | 28+++++++++++++++++++++++++++-
7 files changed, 306 insertions(+), 8 deletions(-)

diff --git a/python/evm_tokenvote/data/Voter.bin b/python/evm_tokenvote/data/Voter.bin @@ -1 +1 @@ -60806040523480156200001157600080fd5b50604051620029a7380380620029a783398181016040528101906200003791906200012a565b816000806101000a81548173ffffffffffffffffffffffffffffffffffffffff021916908373ffffffffffffffffffffffffffffffffffffffff16021790555080600260006101000a81548173ffffffffffffffffffffffffffffffffffffffff021916908373ffffffffffffffffffffffffffffffffffffffff160217905550505062000171565b600080fd5b600073ffffffffffffffffffffffffffffffffffffffff82169050919050565b6000620000f282620000c5565b9050919050565b6200010481620000e5565b81146200011057600080fd5b50565b6000815190506200012481620000f9565b92915050565b60008060408385031215620001445762000143620000c0565b5b6000620001548582860162000113565b9250506020620001678582860162000113565b9150509250929050565b61282680620001816000396000f3fe608060405234801561001057600080fd5b50600436106100c6576000357c01000000000000000000000000000000000000000000000000000000009004806370a082311161008e57806370a082311461019e5780638bb52213146101ce578063b05c65ba146101fe578063ce7460241461022e578063e99a943e1461024c578063fc0c546a1461027c576100c6565b80630121b93f146100cb578063013cf08b146100fb5780632b49d425146101325780634bb278f314610150578063509bd3371461016e575b600080fd5b6100e560048036038101906100e09190611940565b61029a565b6040516100f29190611988565b60405180910390f35b61011560048036038101906101109190611940565b6102ae565b604051610129989796959493929190611a46565b60405180910390f35b61013a61034f565b6040516101479190611ac4565b60405180910390f35b610158610355565b6040516101659190611988565b60405180910390f35b61018860048036038101906101839190611adf565b610522565b6040516101959190611988565b60405180910390f35b6101b860048036038101906101b39190611b4b565b6109fe565b6040516101c59190611ac4565b60405180910390f35b6101e860048036038101906101e39190611ba4565b610a16565b6040516101f59190611988565b60405180910390f35b61021860048036038101906102139190611d95565b610cc1565b6040516102259190611ac4565b60405180910390f35b610236610f5d565b6040516102439190611ac4565b60405180910390f35b61026660048036038101906102619190611e18565b6112e6565b6040516102739190611ac4565b60405180910390f35b610284611300565b6040516102919190611e6b565b60405180910390f35b60006102a7600083610522565b9050919050565b600181815481106102be57600080fd5b90600052602060002090600702016000915090508060000154908060030154908060040154908060050154908060060160009054906101000a900462ffffff16908060060160039054906101000a900473ffffffffffffffffffffffffffffffffffffffff16908060060160179054906101000a900460ff16908060060160189054906101000a900460ff16905088565b60035481565b60008060006001600354815481106103705761036f611e86565b5b90600052602060002090600702019150600060028360060160179054906101000a900460ff161660ff16146103da576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004016103d190611f12565b60405180910390fd5b600060048360060160179054906101000a900460ff161660ff1611610434576040517f08c379a000000000000000000000000000000000000000000000000000000000815260040161042b90611f7e565b60405180910390fd5b600061043f83611324565b0361044f5760009250505061051f565b60028260060160178282829054906101000a900460ff161792506101000a81548160ff021916908360ff1602179055506001600360008282546104929190611fcd565b92505081905550620f424082600401546104ac9190612001565b90508160060160009054906101000a900462ffffff1662ffffff168260030154826104d79190612072565b10156105185760088260060160178282829054906101000a900460ff161792506101000a81548160ff021916908360ff16021790555060009250505061051f565b6001925050505b90565b600080600060606105323361158f565b60016003548154811061054857610547611e86565b5b90600052602060002090600702019250600060018460060160179054906101000a900460ff161660ff16116105b2576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004016105a9906120ef565b60405180910390fd5b60006105bd84611324565b036105ce57600093505050506109f8565b43836005015411610614576040517f08c379a000000000000000000000000000000000000000000000000000000000815260040161060b9061215b565b60405180910390fd5b6000600560003373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1681526020019081526020016000205411156106e057600354600560003373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002054146106df576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004016106d6906121c7565b60405180910390fd5b5b60008360010180549050111561073a5782600101805490508610610739576040517f08c379a000000000000000000000000000000000000000000000000000000000815260040161073090612233565b60405180910390fd5b5b60008054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16333087604051602401610786939291906122b2565b6040516020818303038152906040527f23b872dd000000000000000000000000000000000000000000000000000000007bffffffffffffffffffffffffffffffffffffffffffffffffffffffff19166020820180517bffffffffffffffffffffffffffffffffffffffffffffffffffffffff8381831617835250505050604051610810919061235a565b6000604051808303816000865af19150503d806000811461084d576040519150601f19603f3d011682016040523d82523d6000602084013e610852565b606091505b5080925081935050508161089b576040517f08c379a0000000000000000000000000000000000000000000000000000000008152600401610892906123bd565b60405180910390fd5b808060200190518101906108af9190612409565b9150816108f1576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004016108e890612482565b60405180910390fd5b600354600560003373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1681526020019081526020016000208190555084600460003373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060008282546109869190611fcd565b92505081905550848360040160008282546109a19190611fcd565b925050819055506000836001018054905011156109f057848360020187815481106109cf576109ce611e86565b5b9060005260206000200160008282546109e89190611fcd565b925050819055505b600193505050505b92915050565b60046020528060005260406000206000915090505481565b60008060008060008060008060018a81548110610a3657610a35611e86565b5b906000526020600020906007020196504387600501541115610a8d576040517f08c379a0000000000000000000000000000000000000000000000000000000008152600401610a84906124ee565b60405180910390fd5b600060048860060160179054906101000a900460ff161660ff161115610abd576000975050505050505050610cbb565b6000876001018054905003610b0c5760048760060160178282829054906101000a900460ff161792506101000a81548160ff021916908360ff1602179055506001975050505050505050610cbb565b8660060160189054906101000a900460ff16915086600101805490508983610b34919061250e565b60ff161115610b5357818760010180549050610b509190612543565b98505b8189610b5f919061250e565b98508660060160179054906101000a900460ff1690508195505b8860ff168660ff161015610c0857866002018660ff1681548110610ba057610b9f611e86565b5b90600052602060002001549250600083118015610bbc57508383145b15610bcc57601081179050610be6565b83831115610be5578293508560ff169450601019811690505b5b600182610bf3919061250e565b91508580610c0090612578565b965050610b79565b818760060160186101000a81548160ff021916908360ff160217905550808760060160176101000a81548160ff021916908360ff16021790555086600101805490508760060160189054906101000a900460ff1660ff161015610c965760048760060160178282829054906101000a900460ff161792506101000a81548160ff021916908360ff1602179055505b600060048860060160179054906101000a900460ff161660ff16119750505050505050505b92915050565b6000610ccb6117ab565b600080610100875110610d13576040517f08c379a0000000000000000000000000000000000000000000000000000000008152600401610d0a906125ed565b60405180910390fd5b338360e0019073ffffffffffffffffffffffffffffffffffffffff16908173ffffffffffffffffffffffffffffffffffffffff168152505087836000018181525050868360200181905250848360c0019062ffffff16908162ffffff16815250508543610d809190611fcd565b9050808360a00181815250506001805490509150600183610100019060ff16908160ff16815250506001839080600181540180825580915050600190039060005260206000209060070201600090919091909150600082015181600001556020820151816001019080519060200190610dfa929190611822565b506040820151816002019080519060200190610e1792919061186f565b50606082015181600301556080820151816004015560a0820151816005015560c08201518160060160006101000a81548162ffffff021916908362ffffff16021790555060e08201518160060160036101000a81548173ffffffffffffffffffffffffffffffffffffffff021916908373ffffffffffffffffffffffffffffffffffffffff1602179055506101008201518160060160176101000a81548160ff021916908360ff1602179055506101208201518160060160186101000a81548160ff021916908360ff1602179055505050610f1260018381548110610eff57610efe611e86565b5b9060005260206000209060070201611324565b836060018181525050818562ffffff16827f5a41400aa51d78e9e5ca645b0d045817eaa7d90e4344d773fdbe24ffb183d3ce60405160405180910390a4819350505050949350505050565b600080600060606000600160035481548110610f7c57610f7b611e86565b5b90600052602060002090600702019350600460003373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020549050600354600560003373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020540361109d574384600501541161108057600060028560060160179054906101000a900460ff161660ff161461107b576040517f08c379a0000000000000000000000000000000000000000000000000000000008152600401611072906124ee565b60405180910390fd5b61109c565b80846004016000828254611094919061260d565b925050819055505b5b6000600460003373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020819055506000600560003373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1681526020019081526020016000208190555060008054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff163382604051602401611171929190612641565b6040516020818303038152906040527fa9059cbb000000000000000000000000000000000000000000000000000000007bffffffffffffffffffffffffffffffffffffffffffffffffffffffff19166020820180517bffffffffffffffffffffffffffffffffffffffffffffffffffffffff83818316178352505050506040516111fb919061235a565b6000604051808303816000865af19150503d8060008114611238576040519150601f19603f3d011682016040523d82523d6000602084013e61123d565b606091505b50809350819450505082611286576040517f08c379a000000000000000000000000000000000000000000000000000000000815260040161127d906123bd565b60405180910390fd5b8180602001905181019061129a9190612409565b9250826112dc576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004016112d390612482565b60405180910390fd5b8094505050505090565b600060606112f685828686610cc1565b9150509392505050565b60008054906101000a900473ffffffffffffffffffffffffffffffffffffffff1681565b600080606060008060009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff166040516024016040516020818303038152906040527f18160ddd000000000000000000000000000000000000000000000000000000007bffffffffffffffffffffffffffffffffffffffffffffffffffffffff19166020820180517bffffffffffffffffffffffffffffffffffffffffffffffffffffffff83818316178352505050506040516113f3919061235a565b6000604051808303816000865af19150503d8060008114611430576040519150601f19603f3d011682016040523d82523d6000602084013e611435565b606091505b5080935081945050508261147e576040517f08c379a0000000000000000000000000000000000000000000000000000000008152600401611475906123bd565b60405180910390fd5b81806020019051810190611492919061267f565b9050600081116114d7576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004016114ce906126f8565b60405180910390fd5b60008560030154036114f157808560030181905550611583565b846003015481146115825760208560060160178282829054906101000a900460ff161792506101000a81548160ff021916908360ff16021790555060028560060160178282829054906101000a900460ff161792506101000a81548160ff021916908360ff16021790555060016003600082825461156f9190611fcd565b925050819055506000935050505061158a565b5b8093505050505b919050565b60006060600073ffffffffffffffffffffffffffffffffffffffff16600260009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16036115f05750506117a8565b600260009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168360405160240161163a9190611e6b565b6040516020818303038152906040527f3ef25013000000000000000000000000000000000000000000000000000000007bffffffffffffffffffffffffffffffffffffffffffffffffffffffff19166020820180517bffffffffffffffffffffffffffffffffffffffffffffffffffffffff83818316178352505050506040516116c4919061235a565b6000604051808303816000865af19150503d8060008114611701576040519150601f19603f3d011682016040523d82523d6000602084013e611706565b606091505b5080925081935050508161174f576040517f08c379a000000000000000000000000000000000000000000000000000000000815260040161174690612764565b60405180910390fd5b808060200190518101906117639190612409565b9150816117a5576040517f08c379a000000000000000000000000000000000000000000000000000000000815260040161179c906127d0565b60405180910390fd5b50505b50565b604051806101400160405280600080191681526020016060815260200160608152602001600081526020016000815260200160008152602001600062ffffff168152602001600073ffffffffffffffffffffffffffffffffffffffff168152602001600060ff168152602001600060ff1681525090565b82805482825590600052602060002090810192821561185e579160200282015b8281111561185d578251825591602001919060010190611842565b5b50905061186b91906118bc565b5090565b8280548282559060005260206000209081019282156118ab579160200282015b828111156118aa57825182559160200191906001019061188f565b5b5090506118b891906118d9565b5090565b5b808211156118d55760008160009055506001016118bd565b5090565b5b808211156118f25760008160009055506001016118da565b5090565b6000604051905090565b600080fd5b600080fd5b6000819050919050565b61191d8161190a565b811461192857600080fd5b50565b60008135905061193a81611914565b92915050565b60006020828403121561195657611955611900565b5b60006119648482850161192b565b91505092915050565b60008115159050919050565b6119828161196d565b82525050565b600060208201905061199d6000830184611979565b92915050565b6000819050919050565b6119b6816119a3565b82525050565b6119c58161190a565b82525050565b600062ffffff82169050919050565b6119e3816119cb565b82525050565b600073ffffffffffffffffffffffffffffffffffffffff82169050919050565b6000611a14826119e9565b9050919050565b611a2481611a09565b82525050565b600060ff82169050919050565b611a4081611a2a565b82525050565b600061010082019050611a5c600083018b6119ad565b611a69602083018a6119bc565b611a7660408301896119bc565b611a8360608301886119bc565b611a9060808301876119da565b611a9d60a0830186611a1b565b611aaa60c0830185611a37565b611ab760e0830184611a37565b9998505050505050505050565b6000602082019050611ad960008301846119bc565b92915050565b60008060408385031215611af657611af5611900565b5b6000611b048582860161192b565b9250506020611b158582860161192b565b9150509250929050565b611b2881611a09565b8114611b3357600080fd5b50565b600081359050611b4581611b1f565b92915050565b600060208284031215611b6157611b60611900565b5b6000611b6f84828501611b36565b91505092915050565b611b8181611a2a565b8114611b8c57600080fd5b50565b600081359050611b9e81611b78565b92915050565b60008060408385031215611bbb57611bba611900565b5b6000611bc98582860161192b565b9250506020611bda85828601611b8f565b9150509250929050565b611bed816119a3565b8114611bf857600080fd5b50565b600081359050611c0a81611be4565b92915050565b600080fd5b6000601f19601f8301169050919050565b7f4e487b7100000000000000000000000000000000000000000000000000000000600052604160045260246000fd5b611c5e82611c15565b810181811067ffffffffffffffff82111715611c7d57611c7c611c26565b5b80604052505050565b6000611c906118f6565b9050611c9c8282611c55565b919050565b600067ffffffffffffffff821115611cbc57611cbb611c26565b5b602082029050602081019050919050565b600080fd5b6000611ce5611ce084611ca1565b611c86565b90508083825260208201905060208402830185811115611d0857611d07611ccd565b5b835b81811015611d315780611d1d8882611bfb565b845260208401935050602081019050611d0a565b5050509392505050565b600082601f830112611d5057611d4f611c10565b5b8135611d60848260208601611cd2565b91505092915050565b611d72816119cb565b8114611d7d57600080fd5b50565b600081359050611d8f81611d69565b92915050565b60008060008060808587031215611daf57611dae611900565b5b6000611dbd87828801611bfb565b945050602085013567ffffffffffffffff811115611dde57611ddd611905565b5b611dea87828801611d3b565b9350506040611dfb8782880161192b565b9250506060611e0c87828801611d80565b91505092959194509250565b600080600060608486031215611e3157611e30611900565b5b6000611e3f86828701611bfb565b9350506020611e508682870161192b565b9250506040611e6186828701611d80565b9150509250925092565b6000602082019050611e806000830184611a1b565b92915050565b7f4e487b7100000000000000000000000000000000000000000000000000000000600052603260045260246000fd5b600082825260208201905092915050565b7f4552525f414c52454144595f53544154455f46494e414c000000000000000000600082015250565b6000611efc601783611eb5565b9150611f0782611ec6565b602082019050919050565b60006020820190508181036000830152611f2b81611eef565b9050919050565b7f4552525f5343414e5f4649525354000000000000000000000000000000000000600082015250565b6000611f68600e83611eb5565b9150611f7382611f32565b602082019050919050565b60006020820190508181036000830152611f9781611f5b565b9050919050565b7f4e487b7100000000000000000000000000000000000000000000000000000000600052601160045260246000fd5b6000611fd88261190a565b9150611fe38361190a565b9250828201905080821115611ffb57611ffa611f9e565b5b92915050565b600061200c8261190a565b91506120178361190a565b92508282026120258161190a565b9150828204841483151761203c5761203b611f9e565b5b5092915050565b7f4e487b7100000000000000000000000000000000000000000000000000000000600052601260045260246000fd5b600061207d8261190a565b91506120888361190a565b92508261209857612097612043565b5b828204905092915050565b7f4552525f50524f504f53414c5f494e4143544956450000000000000000000000600082015250565b60006120d9601583611eb5565b91506120e4826120a3565b602082019050919050565b60006020820190508181036000830152612108816120cc565b9050919050565b7f4552525f444541444c494e450000000000000000000000000000000000000000600082015250565b6000612145600c83611eb5565b91506121508261210f565b602082019050919050565b6000602082019050818103600083015261217481612138565b9050919050565b7f4552525f5245434f5645525f4649525354000000000000000000000000000000600082015250565b60006121b1601183611eb5565b91506121bc8261217b565b602082019050919050565b600060208201905081810360008301526121e0816121a4565b9050919050565b7f4552525f4f5054494f4e5f494e56414c49440000000000000000000000000000600082015250565b600061221d601283611eb5565b9150612228826121e7565b602082019050919050565b6000602082019050818103600083015261224c81612210565b9050919050565b6000819050919050565b600061227861227361226e846119e9565b612253565b6119e9565b9050919050565b600061228a8261225d565b9050919050565b600061229c8261227f565b9050919050565b6122ac81612291565b82525050565b60006060820190506122c76000830186611a1b565b6122d460208301856122a3565b6122e160408301846119bc565b949350505050565b600081519050919050565b600081905092915050565b60005b8381101561231d578082015181840152602081019050612302565b60008484015250505050565b6000612334826122e9565b61233e81856122f4565b935061234e8185602086016122ff565b80840191505092915050565b60006123668284612329565b915081905092915050565b7f4552525f544f4b454e0000000000000000000000000000000000000000000000600082015250565b60006123a7600983611eb5565b91506123b282612371565b602082019050919050565b600060208201905081810360008301526123d68161239a565b9050919050565b6123e68161196d565b81146123f157600080fd5b50565b600081519050612403816123dd565b92915050565b60006020828403121561241f5761241e611900565b5b600061242d848285016123f4565b91505092915050565b7f4552525f5452414e534645520000000000000000000000000000000000000000600082015250565b600061246c600c83611eb5565b915061247782612436565b602082019050919050565b6000602082019050818103600083015261249b8161245f565b9050919050565b7f4552525f5052454d415455524500000000000000000000000000000000000000600082015250565b60006124d8600d83611eb5565b91506124e3826124a2565b602082019050919050565b60006020820190508181036000830152612507816124cb565b9050919050565b600061251982611a2a565b915061252483611a2a565b9250828201905060ff81111561253d5761253c611f9e565b5b92915050565b600061254e82611a2a565b915061255983611a2a565b9250828203905060ff81111561257257612571611f9e565b5b92915050565b600061258382611a2a565b915060ff820361259657612595611f9e565b5b600182019050919050565b7f4552525f544f4f5f4d414e595f4f5054494f4e53000000000000000000000000600082015250565b60006125d7601483611eb5565b91506125e2826125a1565b602082019050919050565b60006020820190508181036000830152612606816125ca565b9050919050565b60006126188261190a565b91506126238361190a565b925082820390508181111561263b5761263a611f9e565b5b92915050565b60006040820190506126566000830185611a1b565b61266360208301846119bc565b9392505050565b60008151905061267981611914565b92915050565b60006020828403121561269557612694611900565b5b60006126a38482850161266a565b91505092915050565b7f4552525f5a45524f5f535550504c590000000000000000000000000000000000600082015250565b60006126e2600f83611eb5565b91506126ed826126ac565b602082019050919050565b60006020820190508181036000830152612711816126d5565b9050919050565b7f4552525f52454749535452590000000000000000000000000000000000000000600082015250565b600061274e600c83611eb5565b915061275982612718565b602082019050919050565b6000602082019050818103600083015261277d81612741565b9050919050565b7f4552525f554e415554485f4143434f554e540000000000000000000000000000600082015250565b60006127ba601283611eb5565b91506127c582612784565b602082019050919050565b600060208201905081810360008301526127e9816127ad565b905091905056fea26469706673582212204a1fb70284bfdf4ad9631173605d58e0df3befbd78bf87ff869adc7007dfe1f864736f6c63430008130033 -\ No newline at end of file +60806040523480156200001157600080fd5b5060405162002c8938038062002c8983398181016040528101906200003791906200012a565b816000806101000a81548173ffffffffffffffffffffffffffffffffffffffff021916908373ffffffffffffffffffffffffffffffffffffffff16021790555080600260006101000a81548173ffffffffffffffffffffffffffffffffffffffff021916908373ffffffffffffffffffffffffffffffffffffffff160217905550505062000171565b600080fd5b600073ffffffffffffffffffffffffffffffffffffffff82169050919050565b6000620000f282620000c5565b9050919050565b6200010481620000e5565b81146200011057600080fd5b50565b6000815190506200012481620000f9565b92915050565b60008060408385031215620001445762000143620000c0565b5b6000620001548582860162000113565b9250506020620001678582860162000113565b9150509250929050565b612b0880620001816000396000f3fe608060405234801561001057600080fd5b5060043610610107576000357c01000000000000000000000000000000000000000000000000000000009004806384385191116100a9578063ba32941411610083578063ba329414146102cf578063ce746024146102ff578063e99a943e1461031d578063fc0c546a1461034d57610107565b8063843851911461023f5780638bb522131461026f578063b05c65ba1461029f57610107565b80632b49d425116100e55780632b49d425146101a35780634bb278f3146101c1578063509bd337146101df57806370a082311461020f57610107565b80630121b93f1461010c578063013cf08b1461013c5780631ce3092714610173575b600080fd5b61012660048036038101906101219190611b9b565b61036b565b6040516101339190611be3565b60405180910390f35b61015660048036038101906101519190611b9b565b61037f565b60405161016a989796959493929190611ca1565b60405180910390f35b61018d60048036038101906101889190611d1f565b610420565b60405161019a9190611d5f565b60405180910390f35b6101ab610471565b6040516101b89190611d7a565b60405180910390f35b6101c9610477565b6040516101d69190611be3565b60405180910390f35b6101f960048036038101906101f49190611d1f565b610644565b6040516102069190611be3565b60405180910390f35b61022960048036038101906102249190611dc1565b610b20565b6040516102369190611d7a565b60405180910390f35b61025960048036038101906102549190611b9b565b610b38565b6040516102669190611d7a565b60405180910390f35b61028960048036038101906102849190611e1a565b610b6f565b6040516102969190611be3565b60405180910390f35b6102b960048036038101906102b4919061200b565b610e19565b6040516102c69190611d7a565b60405180910390f35b6102e960048036038101906102e49190611d1f565b611107565b6040516102f69190611d7a565b60405180910390f35b6103076111b8565b6040516103149190611d7a565b60405180910390f35b6103376004803603810190610332919061208e565b611541565b6040516103449190611d7a565b60405180910390f35b61035561155b565b60405161036291906120e1565b60405180910390f35b6000610378600083610644565b9050919050565b6001818154811061038f57600080fd5b90600052602060002090600702016000915090508060000154908060030154908060040154908060050154908060060160009054906101000a900462ffffff16908060060160039054906101000a900473ffffffffffffffffffffffffffffffffffffffff16908060060160179054906101000a900460ff16908060060160189054906101000a900460ff16905088565b60008060018481548110610437576104366120fc565b5b9060005260206000209060070201905080600101838154811061045d5761045c6120fc565b5b906000526020600020015491505092915050565b60035481565b6000806000600160035481548110610492576104916120fc565b5b90600052602060002090600702019150600060028360060160179054906101000a900460ff161660ff16146104fc576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004016104f390612188565b60405180910390fd5b600060048360060160179054906101000a900460ff161660ff1611610556576040517f08c379a000000000000000000000000000000000000000000000000000000000815260040161054d906121f4565b60405180910390fd5b60006105618361157f565b0361057157600092505050610641565b60028260060160178282829054906101000a900460ff161792506101000a81548160ff021916908360ff1602179055506001600360008282546105b49190612243565b92505081905550620f424082600401546105ce9190612277565b90508160060160009054906101000a900462ffffff1662ffffff168260030154826105f991906122e8565b101561063a5760088260060160178282829054906101000a900460ff161792506101000a81548160ff021916908360ff160217905550600092505050610641565b6001925050505b90565b60008060006060610654336117ea565b60016003548154811061066a576106696120fc565b5b90600052602060002090600702019250600060018460060160179054906101000a900460ff161660ff16116106d4576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004016106cb90612365565b60405180910390fd5b60006106df8461157f565b036106f05760009350505050610b1a565b43836005015411610736576040517f08c379a000000000000000000000000000000000000000000000000000000000815260040161072d906123d1565b60405180910390fd5b6000600560003373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002054111561080257600354600560003373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1681526020019081526020016000205414610801576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004016107f89061243d565b60405180910390fd5b5b60008360010180549050111561085c578260010180549050861061085b576040517f08c379a0000000000000000000000000000000000000000000000000000000008152600401610852906124a9565b60405180910390fd5b5b60008054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff163330876040516024016108a893929190612528565b6040516020818303038152906040527f23b872dd000000000000000000000000000000000000000000000000000000007bffffffffffffffffffffffffffffffffffffffffffffffffffffffff19166020820180517bffffffffffffffffffffffffffffffffffffffffffffffffffffffff838183161783525050505060405161093291906125d0565b6000604051808303816000865af19150503d806000811461096f576040519150601f19603f3d011682016040523d82523d6000602084013e610974565b606091505b508092508193505050816109bd576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004016109b490612633565b60405180910390fd5b808060200190518101906109d1919061267f565b915081610a13576040517f08c379a0000000000000000000000000000000000000000000000000000000008152600401610a0a906126f8565b60405180910390fd5b600354600560003373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1681526020019081526020016000208190555084600460003373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1681526020019081526020016000206000828254610aa89190612243565b9250508190555084836004016000828254610ac39190612243565b92505081905550600083600101805490501115610b125784836002018781548110610af157610af06120fc565b5b906000526020600020016000828254610b0a9190612243565b925050819055505b600193505050505b92915050565b60046020528060005260406000206000915090505481565b60008060018381548110610b4f57610b4e6120fc565b5b906000526020600020906007020190508060010180549050915050919050565b60008060008060008060008060018a81548110610b8f57610b8e6120fc565b5b906000526020600020906007020196504387600501541115610be6576040517f08c379a0000000000000000000000000000000000000000000000000000000008152600401610bdd90612764565b60405180910390fd5b600060048860060160179054906101000a900460ff161660ff161115610c16576000975050505050505050610e13565b6000876001018054905003610c655760048760060160178282829054906101000a900460ff161792506101000a81548160ff021916908360ff1602179055506001975050505050505050610e13565b8660060160189054906101000a900460ff16915086600101805490508983610c8d9190612784565b60ff161115610cac57818760010180549050610ca991906127b9565b98505b8189610cb89190612784565b98508660060160179054906101000a900460ff1690508195505b8860ff168660ff161015610d6157866002018660ff1681548110610cf957610cf86120fc565b5b90600052602060002001549250600083118015610d1557508383145b15610d2557601081179050610d3f565b83831115610d3e578293508560ff169450601019811690505b5b600182610d4c9190612784565b91508580610d59906127ee565b965050610cd2565b818760060160186101000a81548160ff021916908360ff160217905550808760060160176101000a81548160ff021916908360ff16021790555086600101805490508760060160189054906101000a900460ff1660ff1610610dee5760048760060160178282829054906101000a900460ff161792506101000a81548160ff021916908360ff1602179055505b600060048860060160179054906101000a900460ff161660ff16119750505050505050505b92915050565b6000610e23611a06565b600080610100875110610e6b576040517f08c379a0000000000000000000000000000000000000000000000000000000008152600401610e6290612863565b60405180910390fd5b338360e0019073ffffffffffffffffffffffffffffffffffffffff16908173ffffffffffffffffffffffffffffffffffffffff168152505087836000018181525050868360200181905250865167ffffffffffffffff811115610ed157610ed0611e9c565b5b604051908082528060200260200182016040528015610eff5781602001602082028036833780820191505090505b508360400181905250848360c0019062ffffff16908162ffffff16815250508543610f2a9190612243565b9050808360a00181815250506001805490509150600183610100019060ff16908160ff16815250506001839080600181540180825580915050600190039060005260206000209060070201600090919091909150600082015181600001556020820151816001019080519060200190610fa4929190611a7d565b506040820151816002019080519060200190610fc1929190611aca565b50606082015181600301556080820151816004015560a0820151816005015560c08201518160060160006101000a81548162ffffff021916908362ffffff16021790555060e08201518160060160036101000a81548173ffffffffffffffffffffffffffffffffffffffff021916908373ffffffffffffffffffffffffffffffffffffffff1602179055506101008201518160060160176101000a81548160ff021916908360ff1602179055506101208201518160060160186101000a81548160ff021916908360ff16021790555050506110bc600183815481106110a9576110a86120fc565b5b906000526020600020906007020161157f565b836060018181525050818562ffffff16827f5a41400aa51d78e9e5ca645b0d045817eaa7d90e4344d773fdbe24ffb183d3ce60405160405180910390a4819350505050949350505050565b6000806001848154811061111e5761111d6120fc565b5b90600052602060002090600702019050600081600101805490500361118d5760008314611180576040517f08c379a0000000000000000000000000000000000000000000000000000000008152600401611177906128cf565b60405180910390fd5b80600401549150506111b2565b8060020183815481106111a3576111a26120fc565b5b90600052602060002001549150505b92915050565b6000806000606060006001600354815481106111d7576111d66120fc565b5b90600052602060002090600702019350600460003373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020549050600354600560003373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002054036112f857438460050154116112db57600060028560060160179054906101000a900460ff161660ff16146112d6576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004016112cd90612764565b60405180910390fd5b6112f7565b808460040160008282546112ef91906128ef565b925050819055505b5b6000600460003373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020819055506000600560003373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1681526020019081526020016000208190555060008054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1633826040516024016113cc929190612923565b6040516020818303038152906040527fa9059cbb000000000000000000000000000000000000000000000000000000007bffffffffffffffffffffffffffffffffffffffffffffffffffffffff19166020820180517bffffffffffffffffffffffffffffffffffffffffffffffffffffffff838183161783525050505060405161145691906125d0565b6000604051808303816000865af19150503d8060008114611493576040519150601f19603f3d011682016040523d82523d6000602084013e611498565b606091505b508093508194505050826114e1576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004016114d890612633565b60405180910390fd5b818060200190518101906114f5919061267f565b925082611537576040517f08c379a000000000000000000000000000000000000000000000000000000000815260040161152e906126f8565b60405180910390fd5b8094505050505090565b6000606061155185828686610e19565b9150509392505050565b60008054906101000a900473ffffffffffffffffffffffffffffffffffffffff1681565b600080606060008060009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff166040516024016040516020818303038152906040527f18160ddd000000000000000000000000000000000000000000000000000000007bffffffffffffffffffffffffffffffffffffffffffffffffffffffff19166020820180517bffffffffffffffffffffffffffffffffffffffffffffffffffffffff838183161783525050505060405161164e91906125d0565b6000604051808303816000865af19150503d806000811461168b576040519150601f19603f3d011682016040523d82523d6000602084013e611690565b606091505b508093508194505050826116d9576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004016116d090612633565b60405180910390fd5b818060200190518101906116ed9190612961565b905060008111611732576040517f08c379a0000000000000000000000000000000000000000000000000000000008152600401611729906129da565b60405180910390fd5b600085600301540361174c578085600301819055506117de565b846003015481146117dd5760208560060160178282829054906101000a900460ff161792506101000a81548160ff021916908360ff16021790555060028560060160178282829054906101000a900460ff161792506101000a81548160ff021916908360ff1602179055506001600360008282546117ca9190612243565b92505081905550600093505050506117e5565b5b8093505050505b919050565b60006060600073ffffffffffffffffffffffffffffffffffffffff16600260009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff160361184b575050611a03565b600260009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168360405160240161189591906120e1565b6040516020818303038152906040527f3ef25013000000000000000000000000000000000000000000000000000000007bffffffffffffffffffffffffffffffffffffffffffffffffffffffff19166020820180517bffffffffffffffffffffffffffffffffffffffffffffffffffffffff838183161783525050505060405161191f91906125d0565b6000604051808303816000865af19150503d806000811461195c576040519150601f19603f3d011682016040523d82523d6000602084013e611961565b606091505b508092508193505050816119aa576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004016119a190612a46565b60405180910390fd5b808060200190518101906119be919061267f565b915081611a00576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004016119f790612ab2565b60405180910390fd5b50505b50565b604051806101400160405280600080191681526020016060815260200160608152602001600081526020016000815260200160008152602001600062ffffff168152602001600073ffffffffffffffffffffffffffffffffffffffff168152602001600060ff168152602001600060ff1681525090565b828054828255906000526020600020908101928215611ab9579160200282015b82811115611ab8578251825591602001919060010190611a9d565b5b509050611ac69190611b17565b5090565b828054828255906000526020600020908101928215611b06579160200282015b82811115611b05578251825591602001919060010190611aea565b5b509050611b139190611b34565b5090565b5b80821115611b30576000816000905550600101611b18565b5090565b5b80821115611b4d576000816000905550600101611b35565b5090565b6000604051905090565b600080fd5b600080fd5b6000819050919050565b611b7881611b65565b8114611b8357600080fd5b50565b600081359050611b9581611b6f565b92915050565b600060208284031215611bb157611bb0611b5b565b5b6000611bbf84828501611b86565b91505092915050565b60008115159050919050565b611bdd81611bc8565b82525050565b6000602082019050611bf86000830184611bd4565b92915050565b6000819050919050565b611c1181611bfe565b82525050565b611c2081611b65565b82525050565b600062ffffff82169050919050565b611c3e81611c26565b82525050565b600073ffffffffffffffffffffffffffffffffffffffff82169050919050565b6000611c6f82611c44565b9050919050565b611c7f81611c64565b82525050565b600060ff82169050919050565b611c9b81611c85565b82525050565b600061010082019050611cb7600083018b611c08565b611cc4602083018a611c17565b611cd16040830189611c17565b611cde6060830188611c17565b611ceb6080830187611c35565b611cf860a0830186611c76565b611d0560c0830185611c92565b611d1260e0830184611c92565b9998505050505050505050565b60008060408385031215611d3657611d35611b5b565b5b6000611d4485828601611b86565b9250506020611d5585828601611b86565b9150509250929050565b6000602082019050611d746000830184611c08565b92915050565b6000602082019050611d8f6000830184611c17565b92915050565b611d9e81611c64565b8114611da957600080fd5b50565b600081359050611dbb81611d95565b92915050565b600060208284031215611dd757611dd6611b5b565b5b6000611de584828501611dac565b91505092915050565b611df781611c85565b8114611e0257600080fd5b50565b600081359050611e1481611dee565b92915050565b60008060408385031215611e3157611e30611b5b565b5b6000611e3f85828601611b86565b9250506020611e5085828601611e05565b9150509250929050565b611e6381611bfe565b8114611e6e57600080fd5b50565b600081359050611e8081611e5a565b92915050565b600080fd5b6000601f19601f8301169050919050565b7f4e487b7100000000000000000000000000000000000000000000000000000000600052604160045260246000fd5b611ed482611e8b565b810181811067ffffffffffffffff82111715611ef357611ef2611e9c565b5b80604052505050565b6000611f06611b51565b9050611f128282611ecb565b919050565b600067ffffffffffffffff821115611f3257611f31611e9c565b5b602082029050602081019050919050565b600080fd5b6000611f5b611f5684611f17565b611efc565b90508083825260208201905060208402830185811115611f7e57611f7d611f43565b5b835b81811015611fa75780611f938882611e71565b845260208401935050602081019050611f80565b5050509392505050565b600082601f830112611fc657611fc5611e86565b5b8135611fd6848260208601611f48565b91505092915050565b611fe881611c26565b8114611ff357600080fd5b50565b60008135905061200581611fdf565b92915050565b6000806000806080858703121561202557612024611b5b565b5b600061203387828801611e71565b945050602085013567ffffffffffffffff81111561205457612053611b60565b5b61206087828801611fb1565b935050604061207187828801611b86565b925050606061208287828801611ff6565b91505092959194509250565b6000806000606084860312156120a7576120a6611b5b565b5b60006120b586828701611e71565b93505060206120c686828701611b86565b92505060406120d786828701611ff6565b9150509250925092565b60006020820190506120f66000830184611c76565b92915050565b7f4e487b7100000000000000000000000000000000000000000000000000000000600052603260045260246000fd5b600082825260208201905092915050565b7f4552525f414c52454144595f53544154455f46494e414c000000000000000000600082015250565b600061217260178361212b565b915061217d8261213c565b602082019050919050565b600060208201905081810360008301526121a181612165565b9050919050565b7f4552525f5343414e5f4649525354000000000000000000000000000000000000600082015250565b60006121de600e8361212b565b91506121e9826121a8565b602082019050919050565b6000602082019050818103600083015261220d816121d1565b9050919050565b7f4e487b7100000000000000000000000000000000000000000000000000000000600052601160045260246000fd5b600061224e82611b65565b915061225983611b65565b925082820190508082111561227157612270612214565b5b92915050565b600061228282611b65565b915061228d83611b65565b925082820261229b81611b65565b915082820484148315176122b2576122b1612214565b5b5092915050565b7f4e487b7100000000000000000000000000000000000000000000000000000000600052601260045260246000fd5b60006122f382611b65565b91506122fe83611b65565b92508261230e5761230d6122b9565b5b828204905092915050565b7f4552525f50524f504f53414c5f494e4143544956450000000000000000000000600082015250565b600061234f60158361212b565b915061235a82612319565b602082019050919050565b6000602082019050818103600083015261237e81612342565b9050919050565b7f4552525f444541444c494e450000000000000000000000000000000000000000600082015250565b60006123bb600c8361212b565b91506123c682612385565b602082019050919050565b600060208201905081810360008301526123ea816123ae565b9050919050565b7f4552525f5245434f5645525f4649525354000000000000000000000000000000600082015250565b600061242760118361212b565b9150612432826123f1565b602082019050919050565b600060208201905081810360008301526124568161241a565b9050919050565b7f4552525f4f5054494f4e5f494e56414c49440000000000000000000000000000600082015250565b600061249360128361212b565b915061249e8261245d565b602082019050919050565b600060208201905081810360008301526124c281612486565b9050919050565b6000819050919050565b60006124ee6124e96124e484611c44565b6124c9565b611c44565b9050919050565b6000612500826124d3565b9050919050565b6000612512826124f5565b9050919050565b61252281612507565b82525050565b600060608201905061253d6000830186611c76565b61254a6020830185612519565b6125576040830184611c17565b949350505050565b600081519050919050565b600081905092915050565b60005b83811015612593578082015181840152602081019050612578565b60008484015250505050565b60006125aa8261255f565b6125b4818561256a565b93506125c4818560208601612575565b80840191505092915050565b60006125dc828461259f565b915081905092915050565b7f4552525f544f4b454e0000000000000000000000000000000000000000000000600082015250565b600061261d60098361212b565b9150612628826125e7565b602082019050919050565b6000602082019050818103600083015261264c81612610565b9050919050565b61265c81611bc8565b811461266757600080fd5b50565b60008151905061267981612653565b92915050565b60006020828403121561269557612694611b5b565b5b60006126a38482850161266a565b91505092915050565b7f4552525f5452414e534645520000000000000000000000000000000000000000600082015250565b60006126e2600c8361212b565b91506126ed826126ac565b602082019050919050565b60006020820190508181036000830152612711816126d5565b9050919050565b7f4552525f5052454d415455524500000000000000000000000000000000000000600082015250565b600061274e600d8361212b565b915061275982612718565b602082019050919050565b6000602082019050818103600083015261277d81612741565b9050919050565b600061278f82611c85565b915061279a83611c85565b9250828201905060ff8111156127b3576127b2612214565b5b92915050565b60006127c482611c85565b91506127cf83611c85565b9250828203905060ff8111156127e8576127e7612214565b5b92915050565b60006127f982611c85565b915060ff820361280c5761280b612214565b5b600182019050919050565b7f4552525f544f4f5f4d414e595f4f5054494f4e53000000000000000000000000600082015250565b600061284d60148361212b565b915061285882612817565b602082019050919050565b6000602082019050818103600083015261287c81612840565b9050919050565b7f4552525f4e4f5f4f5054494f4e53000000000000000000000000000000000000600082015250565b60006128b9600e8361212b565b91506128c482612883565b602082019050919050565b600060208201905081810360008301526128e8816128ac565b9050919050565b60006128fa82611b65565b915061290583611b65565b925082820390508181111561291d5761291c612214565b5b92915050565b60006040820190506129386000830185611c76565b6129456020830184611c17565b9392505050565b60008151905061295b81611b6f565b92915050565b60006020828403121561297757612976611b5b565b5b60006129858482850161294c565b91505092915050565b7f4552525f5a45524f5f535550504c590000000000000000000000000000000000600082015250565b60006129c4600f8361212b565b91506129cf8261298e565b602082019050919050565b600060208201905081810360008301526129f3816129b7565b9050919050565b7f4552525f52454749535452590000000000000000000000000000000000000000600082015250565b6000612a30600c8361212b565b9150612a3b826129fa565b602082019050919050565b60006020820190508181036000830152612a5f81612a23565b9050919050565b7f4552525f554e415554485f4143434f554e540000000000000000000000000000600082015250565b6000612a9c60128361212b565b9150612aa782612a66565b602082019050919050565b60006020820190508181036000830152612acb81612a8f565b905091905056fea26469706673582212203e1bc16f45e04992541388f0e29983fc59f20f2962287a771d4094787411710264736f6c63430008130033 +\ No newline at end of file diff --git a/python/evm_tokenvote/data/Voter.json b/python/evm_tokenvote/data/Voter.json @@ -1 +1 @@ -[{"inputs":[{"internalType":"address","name":"_token","type":"address"},{"internalType":"address","name":"_accountsRegistry","type":"address"}],"stateMutability":"nonpayable","type":"constructor"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"uint256","name":"_blockDeadline","type":"uint256"},{"indexed":true,"internalType":"uint256","name":"voteTargetPpm","type":"uint256"},{"indexed":true,"internalType":"uint256","name":"_proposalIdx","type":"uint256"}],"name":"ProposalAdded","type":"event"},{"inputs":[{"internalType":"address","name":"","type":"address"}],"name":"balanceOf","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"currentProposal","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"finalize","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"","type":"uint256"}],"name":"proposals","outputs":[{"internalType":"bytes32","name":"description","type":"bytes32"},{"internalType":"uint256","name":"supply","type":"uint256"},{"internalType":"uint256","name":"total","type":"uint256"},{"internalType":"uint256","name":"blockDeadline","type":"uint256"},{"internalType":"uint24","name":"targetVotePpm","type":"uint24"},{"internalType":"address","name":"proposer","type":"address"},{"internalType":"uint8","name":"state","type":"uint8"},{"internalType":"uint8","name":"scanCursor","type":"uint8"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"bytes32","name":"_description","type":"bytes32"},{"internalType":"uint256","name":"_blockWait","type":"uint256"},{"internalType":"uint24","name":"_targetVotePpm","type":"uint24"}],"name":"propose","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"bytes32","name":"_description","type":"bytes32"},{"internalType":"bytes32[]","name":"_options","type":"bytes32[]"},{"internalType":"uint256","name":"_blockWait","type":"uint256"},{"internalType":"uint24","name":"_targetVotePpm","type":"uint24"}],"name":"proposeMulti","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"recover","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"_proposalIndex","type":"uint256"},{"internalType":"uint8","name":"_count","type":"uint8"}],"name":"scan","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"token","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"_value","type":"uint256"}],"name":"vote","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"_optionIndex","type":"uint256"},{"internalType":"uint256","name":"_value","type":"uint256"}],"name":"voteOption","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"nonpayable","type":"function"}] +[{"inputs":[{"internalType":"address","name":"_token","type":"address"},{"internalType":"address","name":"_accountsRegistry","type":"address"}],"stateMutability":"nonpayable","type":"constructor"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"uint256","name":"_blockDeadline","type":"uint256"},{"indexed":true,"internalType":"uint256","name":"voteTargetPpm","type":"uint256"},{"indexed":true,"internalType":"uint256","name":"_proposalIdx","type":"uint256"}],"name":"ProposalAdded","type":"event"},{"inputs":[{"internalType":"address","name":"","type":"address"}],"name":"balanceOf","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"currentProposal","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"finalize","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"_proposalIdx","type":"uint256"},{"internalType":"uint256","name":"_optionIdx","type":"uint256"}],"name":"getOption","outputs":[{"internalType":"bytes32","name":"","type":"bytes32"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"_proposalIdx","type":"uint256"}],"name":"optionCount","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"","type":"uint256"}],"name":"proposals","outputs":[{"internalType":"bytes32","name":"description","type":"bytes32"},{"internalType":"uint256","name":"supply","type":"uint256"},{"internalType":"uint256","name":"total","type":"uint256"},{"internalType":"uint256","name":"blockDeadline","type":"uint256"},{"internalType":"uint24","name":"targetVotePpm","type":"uint24"},{"internalType":"address","name":"proposer","type":"address"},{"internalType":"uint8","name":"state","type":"uint8"},{"internalType":"uint8","name":"scanCursor","type":"uint8"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"bytes32","name":"_description","type":"bytes32"},{"internalType":"uint256","name":"_blockWait","type":"uint256"},{"internalType":"uint24","name":"_targetVotePpm","type":"uint24"}],"name":"propose","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"bytes32","name":"_description","type":"bytes32"},{"internalType":"bytes32[]","name":"_options","type":"bytes32[]"},{"internalType":"uint256","name":"_blockWait","type":"uint256"},{"internalType":"uint24","name":"_targetVotePpm","type":"uint24"}],"name":"proposeMulti","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"recover","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"_proposalIndex","type":"uint256"},{"internalType":"uint8","name":"_count","type":"uint8"}],"name":"scan","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"token","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"_value","type":"uint256"}],"name":"vote","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"_proposalIdx","type":"uint256"},{"internalType":"uint256","name":"_optionIdx","type":"uint256"}],"name":"voteCount","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"_optionIndex","type":"uint256"},{"internalType":"uint256","name":"_value","type":"uint256"}],"name":"voteOption","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"nonpayable","type":"function"}] diff --git a/python/evm_tokenvote/data/Voter.metadata.json b/python/evm_tokenvote/data/Voter.metadata.json @@ -1 +1 @@ -{"compiler":{"version":"0.8.19+commit.7dd6d404"},"language":"Solidity","output":{"abi":[{"inputs":[{"internalType":"address","name":"_token","type":"address"},{"internalType":"address","name":"_accountsRegistry","type":"address"}],"stateMutability":"nonpayable","type":"constructor"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"uint256","name":"_blockDeadline","type":"uint256"},{"indexed":true,"internalType":"uint256","name":"voteTargetPpm","type":"uint256"},{"indexed":true,"internalType":"uint256","name":"_proposalIdx","type":"uint256"}],"name":"ProposalAdded","type":"event"},{"inputs":[{"internalType":"address","name":"","type":"address"}],"name":"balanceOf","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"currentProposal","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"finalize","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"","type":"uint256"}],"name":"proposals","outputs":[{"internalType":"bytes32","name":"description","type":"bytes32"},{"internalType":"uint256","name":"supply","type":"uint256"},{"internalType":"uint256","name":"total","type":"uint256"},{"internalType":"uint256","name":"blockDeadline","type":"uint256"},{"internalType":"uint24","name":"targetVotePpm","type":"uint24"},{"internalType":"address","name":"proposer","type":"address"},{"internalType":"uint8","name":"state","type":"uint8"},{"internalType":"uint8","name":"scanCursor","type":"uint8"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"bytes32","name":"_description","type":"bytes32"},{"internalType":"uint256","name":"_blockWait","type":"uint256"},{"internalType":"uint24","name":"_targetVotePpm","type":"uint24"}],"name":"propose","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"bytes32","name":"_description","type":"bytes32"},{"internalType":"bytes32[]","name":"_options","type":"bytes32[]"},{"internalType":"uint256","name":"_blockWait","type":"uint256"},{"internalType":"uint24","name":"_targetVotePpm","type":"uint24"}],"name":"proposeMulti","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"recover","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"_proposalIndex","type":"uint256"},{"internalType":"uint8","name":"_count","type":"uint8"}],"name":"scan","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"token","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"_value","type":"uint256"}],"name":"vote","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"_optionIndex","type":"uint256"},{"internalType":"uint256","name":"_value","type":"uint256"}],"name":"voteOption","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"nonpayable","type":"function"}],"devdoc":{"kind":"dev","methods":{},"version":1},"userdoc":{"kind":"user","methods":{},"version":1}},"settings":{"compilationTarget":{"Voter.sol":"ERC20Vote"},"evmVersion":"byzantium","libraries":{},"metadata":{"bytecodeHash":"ipfs"},"optimizer":{"enabled":false,"runs":200},"remappings":[]},"sources":{"Voter.sol":{"keccak256":"0xdc68a926a68251e02bec8cf1383a18dbbdf8139810b434bea29bbce5784fe92c","license":"AGPL-3.0-or-later","urls":["bzz-raw://17b88e080199bdfd6822168cc27604e85db9251d67a3932457e168811b9a61ca","dweb:/ipfs/QmXmcsFydnHsLW13xp8Arn7BKXB4tRXgLttRiwGhwdSs2g"]}},"version":1} +{"compiler":{"version":"0.8.19+commit.7dd6d404"},"language":"Solidity","output":{"abi":[{"inputs":[{"internalType":"address","name":"_token","type":"address"},{"internalType":"address","name":"_accountsRegistry","type":"address"}],"stateMutability":"nonpayable","type":"constructor"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"uint256","name":"_blockDeadline","type":"uint256"},{"indexed":true,"internalType":"uint256","name":"voteTargetPpm","type":"uint256"},{"indexed":true,"internalType":"uint256","name":"_proposalIdx","type":"uint256"}],"name":"ProposalAdded","type":"event"},{"inputs":[{"internalType":"address","name":"","type":"address"}],"name":"balanceOf","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"currentProposal","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"finalize","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"_proposalIdx","type":"uint256"},{"internalType":"uint256","name":"_optionIdx","type":"uint256"}],"name":"getOption","outputs":[{"internalType":"bytes32","name":"","type":"bytes32"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"_proposalIdx","type":"uint256"}],"name":"optionCount","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"","type":"uint256"}],"name":"proposals","outputs":[{"internalType":"bytes32","name":"description","type":"bytes32"},{"internalType":"uint256","name":"supply","type":"uint256"},{"internalType":"uint256","name":"total","type":"uint256"},{"internalType":"uint256","name":"blockDeadline","type":"uint256"},{"internalType":"uint24","name":"targetVotePpm","type":"uint24"},{"internalType":"address","name":"proposer","type":"address"},{"internalType":"uint8","name":"state","type":"uint8"},{"internalType":"uint8","name":"scanCursor","type":"uint8"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"bytes32","name":"_description","type":"bytes32"},{"internalType":"uint256","name":"_blockWait","type":"uint256"},{"internalType":"uint24","name":"_targetVotePpm","type":"uint24"}],"name":"propose","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"bytes32","name":"_description","type":"bytes32"},{"internalType":"bytes32[]","name":"_options","type":"bytes32[]"},{"internalType":"uint256","name":"_blockWait","type":"uint256"},{"internalType":"uint24","name":"_targetVotePpm","type":"uint24"}],"name":"proposeMulti","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"recover","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"_proposalIndex","type":"uint256"},{"internalType":"uint8","name":"_count","type":"uint8"}],"name":"scan","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"token","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"_value","type":"uint256"}],"name":"vote","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"_proposalIdx","type":"uint256"},{"internalType":"uint256","name":"_optionIdx","type":"uint256"}],"name":"voteCount","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"_optionIndex","type":"uint256"},{"internalType":"uint256","name":"_value","type":"uint256"}],"name":"voteOption","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"nonpayable","type":"function"}],"devdoc":{"kind":"dev","methods":{},"version":1},"userdoc":{"kind":"user","methods":{},"version":1}},"settings":{"compilationTarget":{"Voter.sol":"ERC20Vote"},"evmVersion":"byzantium","libraries":{},"metadata":{"bytecodeHash":"ipfs"},"optimizer":{"enabled":false,"runs":200},"remappings":[]},"sources":{"Voter.sol":{"keccak256":"0xd414694762f43a1bec7c1447e58252c6da02596661c5c748dd582f4b524a20f6","license":"AGPL-3.0-or-later","urls":["bzz-raw://fddab59dd28ec803fa875b3cd01cb42a1985ef37b9daa3573110b683fc695eae","dweb:/ipfs/QmQeTRwAo7XTYq11AmwCkfW3JSvQ3N5uepTPEPW5bARNQ2"]}},"version":1} diff --git a/python/evm_tokenvote/unittest/base.py b/python/evm_tokenvote/unittest/base.py @@ -19,6 +19,8 @@ from evm_tokenvote import Voter logg = logging.getLogger(__name__) hash_of_foo = '2c26b46b68ffc68ff99b453c1d30413413422d706483bfa0f98a5e886266e7ae' +hash_of_bar = 'fcde2b2edba56bf408601fb721fe9b5c338d10ee429ea04fae5511b68fbf8fb9' +hash_of_baz = 'baa5a0964d3320fbc0c6a922140453c8513ea24ab8fd0577034804a967248096' class TestEvmVote(TestGiftableToken): diff --git a/python/evm_tokenvote/voter.py b/python/evm_tokenvote/voter.py @@ -109,15 +109,26 @@ class Voter(TxFactory): - def propose(self, contract_address, sender_address, description, block_deadline, target_vote_ppm=500000, tx_format=TxFormat.JSONRPC, id_generator=None): + def propose(self, contract_address, sender_address, description, block_deadline, target_vote_ppm=500000, options=[], tx_format=TxFormat.JSONRPC, id_generator=None): enc = ABIContractEncoder() - enc.method('propose') + if len(options) == 0: + enc.method('propose') + else: + enc.method('proposeMulti') enc.typ(ABIContractType.BYTES32) + if len(options) > 0: + enc.typ_literal('bytes32[]') enc.typ(ABIContractType.UINT256) enc.typ_literal('uint24') enc.bytes32(description) + if len(options) > 0: + enc.uint256(32*4) enc.uint256(block_deadline) enc.uintn(target_vote_ppm, 24) + if len(options) > 0: + enc.uint256(len(options)) + for v in options: + enc.bytes32(v) data = add_0x(enc.get()) tx = self.template(sender_address, contract_address, use_nonce=True) tx = self.set_code(tx, data) @@ -185,6 +196,62 @@ class Voter(TxFactory): return o + def get_option(self, contract_address, proposal_idx, option_idx, sender_address=ZERO_ADDRESS, id_generator=None): + j = JSONRPCRequest(id_generator) + o = j.template() + o['method'] = 'eth_call' + enc = ABIContractEncoder() + enc.method('getOption') + enc.typ(ABIContractType.UINT256) + enc.typ(ABIContractType.UINT256) + enc.uint256(proposal_idx) + enc.uint256(option_idx) + data = add_0x(enc.get()) + tx = self.template(sender_address, contract_address) + tx = self.set_code(tx, data) + o['params'].append(self.normalize(tx)) + o['params'].append('latest') + o = j.finalize(o) + return o + + + def option_count(self, contract_address, proposal_idx, sender_address=ZERO_ADDRESS, id_generator=None): + j = JSONRPCRequest(id_generator) + o = j.template() + o['method'] = 'eth_call' + enc = ABIContractEncoder() + enc.method('optionCount') + enc.typ(ABIContractType.UINT256) + enc.uint256(proposal_idx) + data = add_0x(enc.get()) + tx = self.template(sender_address, contract_address) + tx = self.set_code(tx, data) + o['params'].append(self.normalize(tx)) + o['params'].append('latest') + o = j.finalize(o) + return o + + + def vote_count(self, contract_address, proposal_idx, option_idx=0, sender_address=ZERO_ADDRESS, id_generator=None): + j = JSONRPCRequest(id_generator) + o = j.template() + o['method'] = 'eth_call' + enc = ABIContractEncoder() + enc.method('voteCount') + enc.typ(ABIContractType.UINT256) + enc.typ(ABIContractType.UINT256) + enc.uint256(proposal_idx) + enc.uint256(option_idx) + data = add_0x(enc.get()) + tx = self.template(sender_address, contract_address) + tx = self.set_code(tx, data) + o['params'].append(self.normalize(tx)) + o['params'].append('latest') + o = j.finalize(o) + return o + + + def current_proposal_idx(self, contract_address, sender_address=ZERO_ADDRESS, id_generator=None): j = JSONRPCRequest(id_generator) o = j.template() @@ -215,7 +282,8 @@ class Voter(TxFactory): dec.typ(ABIContractType.UINT256) # actually uint24 dec.typ(ABIContractType.ADDRESS) dec.typ(ABIContractType.UINT8) - dec.val(v[cursor:cursor+64]) + + dec.val(v[cursor:cursor+64]) # description #cursor += 64 # options pos #cursor += 64 # optionsvotes pos cursor += 64 @@ -230,6 +298,7 @@ class Voter(TxFactory): dec.val(v[cursor:cursor+64]) cursor += 64 dec.val(v[cursor:cursor+64]) + cursor += 64 r = dec.get() o = Proposal(r[0], diff --git a/python/tests/test_option.py b/python/tests/test_option.py @@ -0,0 +1,201 @@ +# standard imports +import unittest +import logging +import os +from chainlib.error import JSONRPCException +from chainlib.eth.nonce import RPCNonceOracle +from chainlib.eth.tx import receipt +from chainlib.eth.block import block_latest +from hexathon import same as same_hex +from eth_erc20 import ERC20 +from giftable_erc20_token import GiftableToken + +# local imports +from evm_tokenvote.unittest import TestEvmVote +from evm_tokenvote.unittest.base import hash_of_foo +from evm_tokenvote.unittest.base import hash_of_bar +from evm_tokenvote.unittest.base import hash_of_baz +from evm_tokenvote import Voter +from evm_tokenvote import ProposalState + + +logging.basicConfig(level=logging.DEBUG) +logg = logging.getLogger() + + +class TestVoteBase(TestEvmVote): + + def test_propose_multi(self): + nonce_oracle = RPCNonceOracle(self.accounts[0], conn=self.conn) + c = Voter(self.chain_spec, signer=self.signer, nonce_oracle=nonce_oracle) + (tx_hash, o) = c.propose(self.voter_address, self.accounts[0], hash_of_foo, 100, options=[hash_of_bar, hash_of_baz]) + self.rpc.do(o) + o = receipt(tx_hash) + r = self.rpc.do(o) + self.assertEqual(r['status'], 1) + + o = c.get_proposal(self.voter_address, 0, sender_address=self.accounts[0]) + r = self.rpc.do(o) + proposal = c.parse_proposal(r) + + o = c.get_option(self.voter_address, 0, 0, sender_address=self.accounts[0]) + r = self.rpc.do(o) + self.assertTrue(same_hex(r, hash_of_bar)) + + o = c.get_option(self.voter_address, 0, 1, sender_address=self.accounts[0]) + r = self.rpc.do(o) + self.assertTrue(same_hex(r, hash_of_baz)) + + with self.assertRaises(JSONRPCException): + o = c.get_option(self.voter_address, 0, 2, sender_address=self.accounts[0]) + r = self.rpc.do(o) + + o = c.option_count(self.voter_address, 0, sender_address=self.accounts[0]) + r = self.rpc.do(o) + count = int(r, 16) + self.assertEqual(count, 2) + + # check that vote count is accessible for the full options index + o = c.vote_count(self.voter_address, 0, 1, sender_address=self.accounts[0]) + r = self.rpc.do(o) + count = int(r, 16) + self.assertEqual(count, 0) + + + def test_vote_multi(self): + third_of_supply = int(self.initial_supply / 3) + nonce_oracle = RPCNonceOracle(self.accounts[0], conn=self.conn) + c = ERC20(self.chain_spec, signer=self.signer, nonce_oracle=nonce_oracle) + (tx_hash, o) = c.transfer(self.address, self.accounts[0], self.alice, third_of_supply) + self.rpc.do(o) + + c = ERC20(self.chain_spec, signer=self.signer, nonce_oracle=nonce_oracle) + (tx_hash, o) = c.transfer(self.address, self.accounts[0], self.bob, third_of_supply) + self.rpc.do(o) + + c = ERC20(self.chain_spec, signer=self.signer, nonce_oracle=nonce_oracle) + (tx_hash, o) = c.transfer(self.address, self.accounts[0], self.carol, third_of_supply) + self.rpc.do(o) + + nonce_oracle = RPCNonceOracle(self.alice, conn=self.conn) + c = ERC20(self.chain_spec, signer=self.signer, nonce_oracle=nonce_oracle) + (tx_hash, o) = c.approve(self.address, self.alice, self.voter_address, third_of_supply) + self.rpc.do(o) + + nonce_oracle = RPCNonceOracle(self.bob, conn=self.conn) + c = ERC20(self.chain_spec, signer=self.signer, nonce_oracle=nonce_oracle) + (tx_hash, o) = c.approve(self.address, self.bob, self.voter_address, third_of_supply) + self.rpc.do(o) + + nonce_oracle = RPCNonceOracle(self.carol, conn=self.conn) + c = ERC20(self.chain_spec, signer=self.signer, nonce_oracle=nonce_oracle) + (tx_hash, o) = c.approve(self.address, self.carol, self.voter_address, third_of_supply) + self.rpc.do(o) + + nonce_oracle = RPCNonceOracle(self.accounts[0], conn=self.conn) + c = Voter(self.chain_spec, signer=self.signer, nonce_oracle=nonce_oracle) + (tx_hash, o) = c.propose(self.voter_address, self.accounts[0], hash_of_foo, 100, options=[hash_of_bar, hash_of_baz]) + self.rpc.do(o) + + o = block_latest() + proposal_block_height = self.rpc.do(o) + + nonce_oracle = RPCNonceOracle(self.alice, conn=self.conn) + c = Voter(self.chain_spec, signer=self.signer, nonce_oracle=nonce_oracle) + (tx_hash, o) = c.vote(self.voter_address, self.alice, third_of_supply, option=1) + self.rpc.do(o) + + nonce_oracle = RPCNonceOracle(self.bob, conn=self.conn) + c = Voter(self.chain_spec, signer=self.signer, nonce_oracle=nonce_oracle) + (tx_hash, o) = c.vote(self.voter_address, self.bob, third_of_supply, option=0) + self.rpc.do(o) + + nonce_oracle = RPCNonceOracle(self.carol, conn=self.conn) + c = Voter(self.chain_spec, signer=self.signer, nonce_oracle=nonce_oracle) + (tx_hash, o) = c.vote(self.voter_address, self.carol, third_of_supply, option=1) + self.rpc.do(o) + + o = block_latest() + now_block_height = self.rpc.do(o) + need_blocks = proposal_block_height + 100 - now_block_height + 1 + self.backend.mine_blocks(need_blocks) + + nonce_oracle = RPCNonceOracle(self.trent, conn=self.conn) + c = Voter(self.chain_spec, signer=self.signer, nonce_oracle=nonce_oracle) + (tx_hash, o) = c.scan(self.voter_address, self.trent, 0, 3) # count is 2, let's check 3 to see if the check catches it + self.rpc.do(o) + + (tx_hash, o) = c.finalize_vote(self.voter_address, self.trent) + self.rpc.do(o) + + o = c.get_proposal(self.voter_address, 0, sender_address=self.accounts[0]) + r = self.rpc.do(o) + proposal = c.parse_proposal(r) + + self.assertEqual(proposal.state & ProposalState.SCANNED, ProposalState.SCANNED) + self.assertEqual(proposal.state & ProposalState.FINAL, ProposalState.FINAL) + self.assertEqual(proposal.state & ProposalState.TIED, 0) + self.assertEqual(proposal.state & ProposalState.INSUFFICIENT, 0) + + + def test_vote_unanimous_fail(self): + third_of_supply = int(self.initial_supply / 3) + nonce_oracle = RPCNonceOracle(self.accounts[0], conn=self.conn) + c = ERC20(self.chain_spec, signer=self.signer, nonce_oracle=nonce_oracle) + (tx_hash, o) = c.transfer(self.address, self.accounts[0], self.alice, third_of_supply) + self.rpc.do(o) + + c = ERC20(self.chain_spec, signer=self.signer, nonce_oracle=nonce_oracle) + (tx_hash, o) = c.transfer(self.address, self.accounts[0], self.bob, third_of_supply) + self.rpc.do(o) + + c = ERC20(self.chain_spec, signer=self.signer, nonce_oracle=nonce_oracle) + (tx_hash, o) = c.transfer(self.address, self.accounts[0], self.carol, third_of_supply) + self.rpc.do(o) + + nonce_oracle = RPCNonceOracle(self.alice, conn=self.conn) + c = ERC20(self.chain_spec, signer=self.signer, nonce_oracle=nonce_oracle) + (tx_hash, o) = c.approve(self.address, self.alice, self.voter_address, third_of_supply) + self.rpc.do(o) + + nonce_oracle = RPCNonceOracle(self.bob, conn=self.conn) + c = ERC20(self.chain_spec, signer=self.signer, nonce_oracle=nonce_oracle) + (tx_hash, o) = c.approve(self.address, self.bob, self.voter_address, third_of_supply) + self.rpc.do(o) + + nonce_oracle = RPCNonceOracle(self.carol, conn=self.conn) + c = ERC20(self.chain_spec, signer=self.signer, nonce_oracle=nonce_oracle) + (tx_hash, o) = c.approve(self.address, self.carol, self.voter_address, third_of_supply) + self.rpc.do(o) + + nonce_oracle = RPCNonceOracle(self.accounts[0], conn=self.conn) + c = Voter(self.chain_spec, signer=self.signer, nonce_oracle=nonce_oracle) + (tx_hash, o) = c.propose(self.voter_address, self.accounts[0], hash_of_foo, 100, target_vote_ppm=1000000, options=[hash_of_bar, hash_of_baz]) + self.rpc.do(o) + + nonce_oracle = RPCNonceOracle(self.alice, conn=self.conn) + c = Voter(self.chain_spec, signer=self.signer, nonce_oracle=nonce_oracle) + (tx_hash, o) = c.vote(self.voter_address, self.alice, third_of_supply, option=1) + self.rpc.do(o) + o = receipt(tx_hash) + r = self.rpc.do(o) + self.assertEqual(r['status'], 1) + + o = c.vote_count(self.voter_address, 0, 0, sender_address=self.accounts[0]) + r = self.rpc.do(o) + count = int(r, 16) + self.assertEqual(count, 0) + + o = c.vote_count(self.voter_address, 0, 1, sender_address=self.accounts[0]) + r = self.rpc.do(o) + count = int(r, 16) + self.assertEqual(count, third_of_supply) + + o = c.get_proposal(self.voter_address, 0, sender_address=self.accounts[0]) + r = self.rpc.do(o) + proposal = c.parse_proposal(r) + self.assertEqual(proposal.state & ProposalState.INSUFFICIENT, ProposalState.INSUFFICIENT) + + +if __name__ == '__main__': + unittest.main() diff --git a/solidity/Voter.sol b/solidity/Voter.sol @@ -56,6 +56,7 @@ contract ERC20Vote { l_proposal.proposer = msg.sender; l_proposal.description = _description; l_proposal.options = _options; + l_proposal.optionVotes = new uint256[](_options.length); l_proposal.targetVotePpm = _targetVotePpm; l_blockDeadline = block.number + _blockWait; l_proposal.blockDeadline = l_blockDeadline; @@ -74,6 +75,31 @@ contract ERC20Vote { return proposeMulti(_description, options, _blockWait, _targetVotePpm); } + function getOption(uint256 _proposalIdx, uint256 _optionIdx) public view returns (bytes32) { + Proposal storage proposal; + + proposal = proposals[_proposalIdx]; + return proposal.options[_optionIdx]; + } + + function optionCount(uint256 _proposalIdx) public view returns(uint256) { + Proposal storage proposal; + + proposal = proposals[_proposalIdx]; + return proposal.options.length; + } + + function voteCount(uint256 _proposalIdx, uint256 _optionIdx) public view returns(uint256) { + Proposal storage proposal; + + proposal = proposals[_proposalIdx]; + if (proposal.options.length == 0) { + require(_optionIdx == 0, "ERR_NO_OPTIONS"); + return proposal.total; + } + return proposal.optionVotes[_optionIdx]; + } + // reverts on unregistered account if an accounts registry has been added. function mustAccount(address _account) private { bool r; @@ -174,7 +200,7 @@ contract ERC20Vote { } proposal.scanCursor = c; proposal.state = state; - if (proposal.scanCursor < proposal.options.length) { + if (proposal.scanCursor >= proposal.options.length) { proposal.state |= STATE_SCANNED; } return proposal.state & STATE_SCANNED > 0;