erc20-transfer-authorization

Simple approval escrow for ERC20 spending
Log | Files | Refs

commit 19eb21569b7d4dca8e92ee17a0a9c12fdcd6c2f7
parent 4a966ef03937baf6ff2c1b108ab29d0f7d3fd094
Author: nolash <dev@holbrook.no>
Date:   Tue, 16 Feb 2021 10:17:48 +0100

WIP Add new quorum tests

Diffstat:
Mpython/erc20_approval_escrow/data/TransferApproval.bin | 4++--
Mpython/erc20_approval_escrow/data/TransferApproval.json | 2+-
Mpython/setup.cfg | 2+-
Apython/tests/base.py | 73+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Mpython/tests/test_app.py | 16++++++++++++----
Apython/tests/test_quorum.py | 90+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Msolidity/TransferApproval.bin | 4++--
Msolidity/TransferApproval.json | 2+-
Msolidity/TransferApproval.sol | 128++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++-----------------
9 files changed, 283 insertions(+), 38 deletions(-)

diff --git a/python/erc20_approval_escrow/data/TransferApproval.bin b/python/erc20_approval_escrow/data/TransferApproval.bin @@ -1 +1 @@ -60806040523480156200001157600080fd5b50604051620016e1380380620016e18339818101604052810190620000379190620001c3565b60005b8151811015620000f35760016004600084848151811062000084577f4e487b7100000000000000000000000000000000000000000000000000000000600052603260045260246000fd5b602002602001015173ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060006101000a81548160ff0219169083151502179055508080620000ea90620002a9565b9150506200003a565b50600180819055506001600281905550506200036f565b6000620001216200011b846200023c565b62000208565b905080838252602082019050828560208602820111156200014157600080fd5b60005b858110156200017557816200015a88826200017f565b84526020840193506020830192505060018101905062000144565b5050509392505050565b600081519050620001908162000355565b92915050565b600082601f830112620001a857600080fd5b8151620001ba8482602086016200010a565b91505092915050565b600060208284031215620001d657600080fd5b600082015167ffffffffffffffff811115620001f157600080fd5b620001ff8482850162000196565b91505092915050565b6000604051905081810181811067ffffffffffffffff8211171562000232576200023162000326565b5b8060405250919050565b600067ffffffffffffffff8211156200025a576200025962000326565b5b602082029050602081019050919050565b600062000278826200027f565b9050919050565b600073ffffffffffffffffffffffffffffffffffffffff82169050919050565b6000819050919050565b6000620002b6826200029f565b91507fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff821415620002ec57620002eb620002f7565b5b600182019050919050565b7f4e487b7100000000000000000000000000000000000000000000000000000000600052601160045260246000fd5b7f4e487b7100000000000000000000000000000000000000000000000000000000600052604160045260246000fd5b62000360816200026b565b81146200036c57600080fd5b50565b611362806200037f6000396000f3fe608060405234801561001057600080fd5b50600436106100935760003560e01c806357ec347a1161006657806357ec347a146101345780636e417c691461015257806381d12c5814610182578063b0addede146101b6578063bac911ac146101e657610093565b806306661abd1461009857806308ae6377146100b65780630a144391146100d45780632d7788db14610104575b600080fd5b6100a0610216565b6040516100ad91906110ef565b60405180910390f35b6100be61021c565b6040516100cb91906110ef565b60405180910390f35b6100ee60048036038101906100e99190610ec7565b610247565b6040516100fb9190611094565b60405180910390f35b61011e60048036038101906101199190610f3f565b610267565b60405161012b9190611094565b60405180910390f35b61013c610553565b60405161014991906110ef565b60405180910390f35b61016c60048036038101906101679190610f3f565b610568565b6040516101799190611094565b60405180910390f35b61019c60048036038101906101979190610f3f565b610855565b6040516101ad95949392919061110a565b60405180910390f35b6101d060048036038101906101cb9190610ef0565b6108eb565b6040516101dd91906110ef565b60405180910390f35b61020060048036038101906101fb9190610f3f565b610b85565b60405161020d91906110ef565b60405180910390f35b60035481565b60008060025460015461022f91906111ad565b141561023e5760009050610244565b60025490505b90565b60046020528060005260406000206000915054906101000a900460ff1681565b6000600460003373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060009054906101000a900460ff166102f5576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004016102ec906110af565b60405180910390fd5b6000806000848152602001908152602001600020905082816000015414610351576040517f08c379a0000000000000000000000000000000000000000000000000000000008152600401610348906110cf565b60405180910390fd5b6000808260030160009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168360010160009054906101000a900473ffffffffffffffffffffffffffffffffffffffff168460010160009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1685600401546040516024016103f09392919061105d565b6040516020818303038152906040527f23b872dd000000000000000000000000000000000000000000000000000000007bffffffffffffffffffffffffffffffffffffffffffffffffffffffff19166020820180517bffffffffffffffffffffffffffffffffffffffffffffffffffffffff838183161783525050505060405161047a9190611046565b6000604051808303816000865af19150503d80600081146104b7576040519150601f19603f3d011682016040523d82523d6000602084013e6104bc565b606091505b50915091506104ce8360000154610d24565b8115610510577f607c56ea76669e46679e89091227c1a3f91841a4cf7588d5a6c84555fb59fdfd8560405161050391906110ef565b60405180910390a1610548565b7fdab20a0fcd702cf875c2d715d5c3fc99af66a716c94b3405408c94b7311c99eb8560405161053f91906110ef565b60405180910390a15b819350505050919050565b60006001805461056391906111ad565b905090565b6000600460003373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060009054906101000a900460ff166105f6576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004016105ed906110af565b60405180910390fd5b600080600084815260200190815260200160002090506000816000015411610653576040517f08c379a000000000000000000000000000000000000000000000000000000000815260040161064a906110cf565b60405180910390fd5b6000808260030160009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168360010160009054906101000a900473ffffffffffffffffffffffffffffffffffffffff168460020160009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1685600401546040516024016106f29392919061105d565b6040516020818303038152906040527f23b872dd000000000000000000000000000000000000000000000000000000007bffffffffffffffffffffffffffffffffffffffffffffffffffffffff19166020820180517bffffffffffffffffffffffffffffffffffffffffffffffffffffffff838183161783525050505060405161077c9190611046565b6000604051808303816000865af19150503d80600081146107b9576040519150601f19603f3d011682016040523d82523d6000602084013e6107be565b606091505b50915091506107d08360000154610d24565b8115610812577f607c56ea76669e46679e89091227c1a3f91841a4cf7588d5a6c84555fb59fdfd8560405161080591906110ef565b60405180910390a161084a565b7fdab20a0fcd702cf875c2d715d5c3fc99af66a716c94b3405408c94b7311c99eb8560405161084191906110ef565b60405180910390a15b819350505050919050565b60006020528060005260406000206000915090508060000154908060010160009054906101000a900473ffffffffffffffffffffffffffffffffffffffff16908060020160009054906101000a900473ffffffffffffffffffffffffffffffffffffffff16908060030160009054906101000a900473ffffffffffffffffffffffffffffffffffffffff16908060040154905085565b60006108f5610e2c565b60015481600001818152505084816040019073ffffffffffffffffffffffffffffffffffffffff16908173ffffffffffffffffffffffffffffffffffffffff168152505033816020019073ffffffffffffffffffffffffffffffffffffffff16908173ffffffffffffffffffffffffffffffffffffffff168152505083816060019073ffffffffffffffffffffffffffffffffffffffff16908173ffffffffffffffffffffffffffffffffffffffff1681525050828160800181815250508060008060015481526020019081526020016000206000820151816000015560208201518160010160006101000a81548173ffffffffffffffffffffffffffffffffffffffff021916908373ffffffffffffffffffffffffffffffffffffffff16021790555060408201518160020160006101000a81548173ffffffffffffffffffffffffffffffffffffffff021916908373ffffffffffffffffffffffffffffffffffffffff16021790555060608201518160030160006101000a81548173ffffffffffffffffffffffffffffffffffffffff021916908373ffffffffffffffffffffffffffffffffffffffff1602179055506080820151816004015590505060036000815480929190610ac790611286565b919050555060016000815480929190610adf90611286565b9190505550806060015173ffffffffffffffffffffffffffffffffffffffff16816040015173ffffffffffffffffffffffffffffffffffffffff16826020015173ffffffffffffffffffffffffffffffffffffffff167fb609ae609609ee99268d05bc1371102cafe8d6b964bf082439ab16be2a01c87c84608001518560000151604051610b6e92919061115d565b60405180910390a480600001519150509392505050565b600080600060025490505b600154811015610d185760008060008381526020019081526020016000206040518060a0016040529081600082015481526020016001820160009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1681526020016002820160009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1681526020016003820160009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1681526020016004820154815250509050600081600001511115610d045784831415610cf55780600001519350505050610d1f565b8280610d0090611286565b9350505b508080610d1090611286565b915050610b90565b5060009150505b919050565b6000808281526020019081526020016000206000808201600090556001820160006101000a81549073ffffffffffffffffffffffffffffffffffffffff02191690556002820160006101000a81549073ffffffffffffffffffffffffffffffffffffffff02191690556003820160006101000a81549073ffffffffffffffffffffffffffffffffffffffff02191690556004820160009055505060036000815480929190610dd19061125c565b919050555060006003541115610e1f57600254811415610e1a576000610df76000610b85565b90506000811415610e1057600154600281905550610e18565b806002819055505b505b610e29565b6001546002819055505b50565b6040518060a0016040528060008152602001600073ffffffffffffffffffffffffffffffffffffffff168152602001600073ffffffffffffffffffffffffffffffffffffffff168152602001600073ffffffffffffffffffffffffffffffffffffffff168152602001600081525090565b600081359050610eac816112fe565b92915050565b600081359050610ec181611315565b92915050565b600060208284031215610ed957600080fd5b6000610ee784828501610e9d565b91505092915050565b600080600060608486031215610f0557600080fd5b6000610f1386828701610e9d565b9350506020610f2486828701610e9d565b9250506040610f3586828701610eb2565b9150509250925092565b600060208284031215610f5157600080fd5b6000610f5f84828501610eb2565b91505092915050565b610f71816111e1565b82525050565b610f80816111f3565b82525050565b6000610f9182611186565b610f9b8185611191565b9350610fab818560208601611229565b80840191505092915050565b6000610fc4600d8361119c565b91507f4552525f4e4f5f414343455353000000000000000000000000000000000000006000830152602082019050919050565b600061100460138361119c565b91507f4552525f494e56414c49445f52455155455354000000000000000000000000006000830152602082019050919050565b6110408161121f565b82525050565b60006110528284610f86565b915081905092915050565b60006060820190506110726000830186610f68565b61107f6020830185610f68565b61108c6040830184611037565b949350505050565b60006020820190506110a96000830184610f77565b92915050565b600060208201905081810360008301526110c881610fb7565b9050919050565b600060208201905081810360008301526110e881610ff7565b9050919050565b60006020820190506111046000830184611037565b92915050565b600060a08201905061111f6000830188611037565b61112c6020830187610f68565b6111396040830186610f68565b6111466060830185610f68565b6111536080830184611037565b9695505050505050565b60006040820190506111726000830185611037565b61117f6020830184611037565b9392505050565b600081519050919050565b600081905092915050565b600082825260208201905092915050565b60006111b88261121f565b91506111c38361121f565b9250828210156111d6576111d56112cf565b5b828203905092915050565b60006111ec826111ff565b9050919050565b60008115159050919050565b600073ffffffffffffffffffffffffffffffffffffffff82169050919050565b6000819050919050565b60005b8381101561124757808201518184015260208101905061122c565b83811115611256576000848401525b50505050565b60006112678261121f565b9150600082141561127b5761127a6112cf565b5b600182039050919050565b60006112918261121f565b91507fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff8214156112c4576112c36112cf565b5b600182019050919050565b7f4e487b7100000000000000000000000000000000000000000000000000000000600052601160045260246000fd5b611307816111e1565b811461131257600080fd5b50565b61131e8161121f565b811461132957600080fd5b5056fea2646970667358221220334bc774a46af5bb91c82b6abec3cf6a0abab29376b9f3e605be99d2965f131564736f6c63430008000033 -\ No newline at end of file +60806040523480156200001157600080fd5b5033600160006101000a81548173ffffffffffffffffffffffffffffffffffffffff021916908373ffffffffffffffffffffffffffffffffffffffff16021790555060016003819055506001600481905550600160068190555060016008819055506200008760016000620000a060201b60201c565b5062000099336200012b60201b60201c565b50620003d2565b6000600854831115620000b257600080fd5b60008311620000c057600080fd5b600854821115620000d057600080fd5b82600681905550816007819055507f9f40cfd22fe91777c78f252bd21a710f3fb007dc2f321876891e7644ba0ae1756006546007546008546040516200011993929190620002da565b60405180910390a16001905092915050565b6000600160009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff163373ffffffffffffffffffffffffffffffffffffffff16146200018857600080fd5b60001515600960008473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060009054906101000a900460ff16151514620001e657600080fd5b6001600960008473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060006101000a81548160ff02191690831515021790555060086000815480929190620002539062000355565b91905055507f47d1c22a25bb3a5d4e481b9b1e6944c2eade3181a0a20b495ed61d35b5323f2482604051620002899190620002bd565b60405180910390a16008549050919050565b620002a68162000317565b82525050565b620002b7816200034b565b82525050565b6000602082019050620002d460008301846200029b565b92915050565b6000606082019050620002f16000830186620002ac565b620003006020830185620002ac565b6200030f6040830184620002ac565b949350505050565b600062000324826200032b565b9050919050565b600073ffffffffffffffffffffffffffffffffffffffff82169050919050565b6000819050919050565b600062000362826200034b565b91507fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff821415620003985762000397620003a3565b5b600182019050919050565b7f4e487b7100000000000000000000000000000000000000000000000000000000600052601160045260246000fd5b611ae280620003e26000396000f3fe608060405234801561001057600080fd5b50600436106101005760003560e01c80636e417c6911610097578063b0addede11610066578063b0addede146102e2578063bac911ac14610312578063e3064a7714610342578063eb12d61e1461037257610100565b80636e417c691461022b578063736c0d5b1461025b57806381d12c581461028b5780638da5cb5b146102c457610100565b80634797569a116100d35780634797569a1461018f57806357ec347a146101bf57806358d71f82146101dd578063614f427f1461020d57610100565b806306661abd1461010557806308ae6377146101235780630e316ab7146101415780631703a01814610171575b600080fd5b61010d6103a2565b60405161011a91906117e2565b60405180910390f35b61012b6103a8565b60405161013891906117e2565b60405180910390f35b61015b60048036038101906101569190611554565b6103d3565b60405161016891906117e2565b60405180910390f35b6101796105ce565b60405161018691906117e2565b60405180910390f35b6101a960048036038101906101a491906115cc565b6105d4565b6040516101b691906117e2565b60405180910390f35b6101c761083e565b6040516101d491906117e2565b60405180910390f35b6101f760048036038101906101f291906115cc565b610854565b60405161020491906117e2565b60405180910390f35b610215610a0c565b60405161022291906117e2565b60405180910390f35b610245600480360381019061024091906115cc565b610a12565b6040516102529190611787565b60405180910390f35b61027560048036038101906102709190611554565b610ceb565b6040516102829190611787565b60405180910390f35b6102a560048036038101906102a091906115cc565b610d0b565b6040516102bb9a999897969594939291906117fd565b60405180910390f35b6102cc610dcc565b6040516102d99190611735565b60405180910390f35b6102fc60048036038101906102f7919061157d565b610df2565b60405161030991906117e2565b60405180910390f35b61032c600480360381019061032791906115cc565b6110e7565b60405161033991906117e2565b60405180910390f35b61035c600480360381019061035791906115f5565b611166565b6040516103699190611787565b60405180910390f35b61038c60048036038101906103879190611554565b6111ec565b60405161039991906117e2565b60405180910390f35b60055481565b6000806004546003546103bb9190611920565b14156103ca57600090506103d0565b60045490505b90565b6000600160009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168273ffffffffffffffffffffffffffffffffffffffff16141561043057600080fd5b600160009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff163373ffffffffffffffffffffffffffffffffffffffff1614806104b757508173ffffffffffffffffffffffffffffffffffffffff163373ffffffffffffffffffffffffffffffffffffffff16145b6104c057600080fd5b60011515600960008473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060009054906101000a900460ff1615151461051d57600080fd5b6000600960008473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060006101000a81548160ff02191690831515021790555060086000815480929190610588906119dc565b91905055507f3525e22824a8a7df2c9a6029941c824cf95b6447f1e13d5128fd3826d35afe8b826040516105bc9190611735565b60405180910390a16008549050919050565b60065481565b60008060026000848152602001908152602001600020905060008160090160009054906101000a900460000b60000b1461060d57600080fd5b600080600085815260200190815260200160002060003373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060009054906101000a900460000b60000b1461067957600080fd5b600160008085815260200190815260200160002060003373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060006101000a81548160ff021916908360000b60ff1602179055508060080160008154809291906106fa90611a06565b9190505550806005015481600801546008546107169190611920565b1415610798577fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff8160090160006101000a81548160ff021916908360000b60ff1602179055507f94064f919a02d0565c6790e0615fb4ba6cf1be1dd679f0161be914613a1b9bb58360405161078b91906117e2565b60405180910390a1610831565b600081600601541180156107b3575080600601548160080154145b15610830577fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff8160090160006101000a81548160ff021916908360000b60ff1602179055507f2ae00ba9813199478b6f22f0c9b606daa70f8efc319c8d2fa6af63f66ea317638360405161082791906117e2565b60405180910390a15b5b8060080154915050919050565b6000600160035461084f9190611920565b905090565b60008060026000848152602001908152602001600020905060008160090160009054906101000a900460000b60000b1461088d57600080fd5b600080600085815260200190815260200160002060003373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060009054906101000a900460000b60000b146108f957600080fd5b600160008085815260200190815260200160002060003373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060006101000a81548160ff021916908360000b60ff16021790555080600701600081548092919061097a90611a06565b9190505550806005015481600701546008546109969190611920565b14156109ff5760018160090160006101000a81548160ff021916908360000b60ff1602179055507f3ad93af63cb7967b23e4fb500b7d7d28b07516325dcf341f88bebf959d82c1cb836040516109ec91906117e2565b60405180910390a16109fd83610a12565b505b8060070154915050919050565b60075481565b6000806002600084815260200190815260200160002090506000816000015411610a71576040517f08c379a0000000000000000000000000000000000000000000000000000000008152600401610a68906117a2565b60405180910390fd5b60018160090160009054906101000a900460000b60000b14610ac8576040517f08c379a0000000000000000000000000000000000000000000000000000000008152600401610abf906117c2565b60405180910390fd5b60028160090160006101000a81548160ff021916908360000b60ff1602179055506000808260030160009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168360010160009054906101000a900473ffffffffffffffffffffffffffffffffffffffff168460020160009054906101000a900473ffffffffffffffffffffffffffffffffffffffff168560040154604051602401610b8893929190611750565b6040516020818303038152906040527f23b872dd000000000000000000000000000000000000000000000000000000007bffffffffffffffffffffffffffffffffffffffffffffffffffffffff19166020820180517bffffffffffffffffffffffffffffffffffffffffffffffffffffffff8381831617835250505050604051610c12919061171e565b6000604051808303816000865af19150503d8060008114610c4f576040519150601f19603f3d011682016040523d82523d6000602084013e610c54565b606091505b5091509150610c668360000154611356565b8115610ca8577fbcf6a68a2f901be4a23a41b53acd7697893a7e34def4e28acba584da75283b6785604051610c9b91906117e2565b60405180910390a1610ce0565b7fdab20a0fcd702cf875c2d715d5c3fc99af66a716c94b3405408c94b7311c99eb85604051610cd791906117e2565b60405180910390a15b819350505050919050565b60096020528060005260406000206000915054906101000a900460ff1681565b60026020528060005260406000206000915090508060000154908060010160009054906101000a900473ffffffffffffffffffffffffffffffffffffffff16908060020160009054906101000a900473ffffffffffffffffffffffffffffffffffffffff16908060030160009054906101000a900473ffffffffffffffffffffffffffffffffffffffff16908060040154908060050154908060060154908060070154908060080154908060090160009054906101000a900460000b90508a565b600160009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1681565b6000610dfc611493565b60035481600001818152505084816040019073ffffffffffffffffffffffffffffffffffffffff16908173ffffffffffffffffffffffffffffffffffffffff168152505033816020019073ffffffffffffffffffffffffffffffffffffffff16908173ffffffffffffffffffffffffffffffffffffffff168152505083816060019073ffffffffffffffffffffffffffffffffffffffff16908173ffffffffffffffffffffffffffffffffffffffff1681525050828160800181815250506006548160a0018181525050806002600060035481526020019081526020016000206000820151816000015560208201518160010160006101000a81548173ffffffffffffffffffffffffffffffffffffffff021916908373ffffffffffffffffffffffffffffffffffffffff16021790555060408201518160020160006101000a81548173ffffffffffffffffffffffffffffffffffffffff021916908373ffffffffffffffffffffffffffffffffffffffff16021790555060608201518160030160006101000a81548173ffffffffffffffffffffffffffffffffffffffff021916908373ffffffffffffffffffffffffffffffffffffffff1602179055506080820151816004015560a0820151816005015560c0820151816006015560e0820151816007015561010082015181600801556101208201518160090160006101000a81548160ff021916908360000b60ff1602179055509050506005600081548092919061102990611a06565b91905055506003600081548092919061104190611a06565b9190505550806060015173ffffffffffffffffffffffffffffffffffffffff16816040015173ffffffffffffffffffffffffffffffffffffffff16826020015173ffffffffffffffffffffffffffffffffffffffff167fb609ae609609ee99268d05bc1371102cafe8d6b964bf082439ab16be2a01c87c846080015185600001516040516110d0929190611899565b60405180910390a480600001519150509392505050565b600080600060045490505b60035481101561115a57600060026000838152602001908152602001600020905060008160000154111561114657848314156111375780600001549350505050611161565b828061114290611a06565b9350505b50808061115290611a06565b9150506110f2565b5060009150505b919050565b600060085483111561117757600080fd5b6000831161118457600080fd5b60085482111561119357600080fd5b82600681905550816007819055507f9f40cfd22fe91777c78f252bd21a710f3fb007dc2f321876891e7644ba0ae1756006546007546008546040516111da939291906118c2565b60405180910390a16001905092915050565b6000600160009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff163373ffffffffffffffffffffffffffffffffffffffff161461124857600080fd5b60001515600960008473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060009054906101000a900460ff161515146112a557600080fd5b6001600960008473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060006101000a81548160ff0219169083151502179055506008600081548092919061131090611a06565b91905055507f47d1c22a25bb3a5d4e481b9b1e6944c2eade3181a0a20b495ed61d35b5323f24826040516113449190611735565b60405180910390a16008549050919050565b600260008281526020019081526020016000206000808201600090556001820160006101000a81549073ffffffffffffffffffffffffffffffffffffffff02191690556002820160006101000a81549073ffffffffffffffffffffffffffffffffffffffff02191690556003820160006101000a81549073ffffffffffffffffffffffffffffffffffffffff0219169055600482016000905560058201600090556006820160009055600782016000905560088201600090556009820160006101000a81549060ff0219169055505060056000815480929190611438906119dc565b9190505550600060055411156114865760045481141561148157600061145e60006110e7565b905060008114156114775760035460048190555061147f565b806004819055505b505b611490565b6003546004819055505b50565b60405180610140016040528060008152602001600073ffffffffffffffffffffffffffffffffffffffff168152602001600073ffffffffffffffffffffffffffffffffffffffff168152602001600073ffffffffffffffffffffffffffffffffffffffff16815260200160008152602001600081526020016000815260200160008152602001600081526020016000800b81525090565b60008135905061153981611a7e565b92915050565b60008135905061154e81611a95565b92915050565b60006020828403121561156657600080fd5b60006115748482850161152a565b91505092915050565b60008060006060848603121561159257600080fd5b60006115a08682870161152a565b93505060206115b18682870161152a565b92505060406115c28682870161153f565b9150509250925092565b6000602082840312156115de57600080fd5b60006115ec8482850161153f565b91505092915050565b6000806040838503121561160857600080fd5b60006116168582860161153f565b92505060206116278582860161153f565b9150509250929050565b61163a81611954565b82525050565b61164981611966565b82525050565b600061165a826118f9565b6116648185611904565b93506116748185602086016119a9565b80840191505092915050565b61168981611972565b82525050565b600061169c60138361190f565b91507f4552525f494e56414c49445f52455155455354000000000000000000000000006000830152602082019050919050565b60006116dc60108361190f565b91507f4552525f4e4f545f454e444f52534544000000000000000000000000000000006000830152602082019050919050565b6117188161199f565b82525050565b600061172a828461164f565b915081905092915050565b600060208201905061174a6000830184611631565b92915050565b60006060820190506117656000830186611631565b6117726020830185611631565b61177f604083018461170f565b949350505050565b600060208201905061179c6000830184611640565b92915050565b600060208201905081810360008301526117bb8161168f565b9050919050565b600060208201905081810360008301526117db816116cf565b9050919050565b60006020820190506117f7600083018461170f565b92915050565b600061014082019050611813600083018d61170f565b611820602083018c611631565b61182d604083018b611631565b61183a606083018a611631565b611847608083018961170f565b61185460a083018861170f565b61186160c083018761170f565b61186e60e083018661170f565b61187c61010083018561170f565b61188a610120830184611680565b9b9a5050505050505050505050565b60006040820190506118ae600083018561170f565b6118bb602083018461170f565b9392505050565b60006060820190506118d7600083018661170f565b6118e4602083018561170f565b6118f1604083018461170f565b949350505050565b600081519050919050565b600081905092915050565b600082825260208201905092915050565b600061192b8261199f565b91506119368361199f565b92508282101561194957611948611a4f565b5b828203905092915050565b600061195f8261197f565b9050919050565b60008115159050919050565b60008160000b9050919050565b600073ffffffffffffffffffffffffffffffffffffffff82169050919050565b6000819050919050565b60005b838110156119c75780820151818401526020810190506119ac565b838111156119d6576000848401525b50505050565b60006119e78261199f565b915060008214156119fb576119fa611a4f565b5b600182039050919050565b6000611a118261199f565b91507fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff821415611a4457611a43611a4f565b5b600182019050919050565b7f4e487b7100000000000000000000000000000000000000000000000000000000600052601160045260246000fd5b611a8781611954565b8114611a9257600080fd5b50565b611a9e8161199f565b8114611aa957600080fd5b5056fea2646970667358221220bb3ffd404eab5da5b2ec1981c136a2879accb2c218a5a3d6bd9c9adcd5f8744e64736f6c63430008000033 +\ No newline at end of file diff --git a/python/erc20_approval_escrow/data/TransferApproval.json b/python/erc20_approval_escrow/data/TransferApproval.json @@ -1 +1 @@ -[{"inputs":[{"internalType":"address[]","name":"_approvers","type":"address[]"}],"stateMutability":"nonpayable","type":"constructor"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"uint256","name":"serial","type":"uint256"}],"name":"NewExecution","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"uint256","name":"serial","type":"uint256"}],"name":"NewRejection","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"_sender","type":"address"},{"indexed":true,"internalType":"address","name":"_recipient","type":"address"},{"indexed":true,"internalType":"address","name":"_token","type":"address"},{"indexed":false,"internalType":"uint256","name":"_value","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"_serial","type":"uint256"}],"name":"NewRequest","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"uint256","name":"serial","type":"uint256"}],"name":"TransferFail","type":"event"},{"inputs":[{"internalType":"address","name":"","type":"address"}],"name":"approvers","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"count","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"_recipient","type":"address"},{"internalType":"address","name":"_token","type":"address"},{"internalType":"uint256","name":"_value","type":"uint256"}],"name":"createRequest","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"_serial","type":"uint256"}],"name":"executeRequest","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"_idx","type":"uint256"}],"name":"getSerialAt","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"lastSerial","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"nextSerial","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"_serial","type":"uint256"}],"name":"rejectRequest","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"","type":"uint256"}],"name":"requests","outputs":[{"internalType":"uint256","name":"serial","type":"uint256"},{"internalType":"address","name":"sender","type":"address"},{"internalType":"address","name":"recipient","type":"address"},{"internalType":"address","name":"token","type":"address"},{"internalType":"uint256","name":"value","type":"uint256"}],"stateMutability":"view","type":"function"}] +[{"inputs":[],"stateMutability":"nonpayable","type":"constructor"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"uint256","name":"_serial","type":"uint256"}],"name":"Approved","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"uint256","name":"_serial","type":"uint256"}],"name":"Executed","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"_sender","type":"address"},{"indexed":true,"internalType":"address","name":"_recipient","type":"address"},{"indexed":true,"internalType":"address","name":"_token","type":"address"},{"indexed":false,"internalType":"uint256","name":"_value","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"_serial","type":"uint256"}],"name":"NewRequest","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"uint256","name":"_quorum","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"_vetoThreshold","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"_signerCount","type":"uint256"}],"name":"QuorumSet","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"uint256","name":"_serial","type":"uint256"}],"name":"Rejected","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"address","name":"_signer","type":"address"}],"name":"SignerAdded","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"address","name":"_signer","type":"address"}],"name":"SignerRemoved","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"uint256","name":"_serial","type":"uint256"}],"name":"TransferFail","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"uint256","name":"_serial","type":"uint256"}],"name":"Vetoed","type":"event"},{"inputs":[{"internalType":"address","name":"_signer","type":"address"}],"name":"addSigner","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"count","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"_recipient","type":"address"},{"internalType":"address","name":"_token","type":"address"},{"internalType":"uint256","name":"_value","type":"uint256"}],"name":"createRequest","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"_serial","type":"uint256"}],"name":"executeRequest","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"_idx","type":"uint256"}],"name":"getSerialAt","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"lastSerial","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"_serial","type":"uint256"}],"name":"nay","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"nextSerial","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"owner","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"quorum","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"_signer","type":"address"}],"name":"removeSigner","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"","type":"uint256"}],"name":"requests","outputs":[{"internalType":"uint256","name":"serial","type":"uint256"},{"internalType":"address","name":"sender","type":"address"},{"internalType":"address","name":"recipient","type":"address"},{"internalType":"address","name":"token","type":"address"},{"internalType":"uint256","name":"value","type":"uint256"},{"internalType":"uint256","name":"quorum","type":"uint256"},{"internalType":"uint256","name":"vetoThreshold","type":"uint256"},{"internalType":"uint256","name":"yay","type":"uint256"},{"internalType":"uint256","name":"nay","type":"uint256"},{"internalType":"int8","name":"result","type":"int8"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"_quorum","type":"uint256"},{"internalType":"uint256","name":"_vetoThreshold","type":"uint256"}],"name":"setThresholds","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"","type":"address"}],"name":"signers","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"vetoThreshold","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"_serial","type":"uint256"}],"name":"yay","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"nonpayable","type":"function"}] diff --git a/python/setup.cfg b/python/setup.cfg @@ -1,6 +1,6 @@ [metadata] name = erc20-approval-escrow -version = 0.3.0a5 +version = 0.3.0a6 description = Simple approval escrow for ERC20 spend approval author = Louis Holbrook author_email = dev@holbrook.no diff --git a/python/tests/base.py b/python/tests/base.py @@ -0,0 +1,73 @@ +import os +import unittest +import json +import logging + +import web3 +import eth_tester +import eth_abi + +logging.basicConfig(level=logging.DEBUG) +logg = logging.getLogger() + +logging.getLogger('web3').setLevel(logging.WARNING) +logging.getLogger('eth.vm').setLevel(logging.WARNING) + +testdir = os.path.dirname(__file__) + + +class TestBase(unittest.TestCase): + + contract = None + + def setUp(self): + eth_params = eth_tester.backends.pyevm.main.get_default_genesis_params({ + 'gas_limit': 9000000, + }) + + f = open(os.path.join(testdir, '../erc20_approval_escrow/data/TransferApproval.bin'), 'r') + bytecode = f.read() + f.close() + + f = open(os.path.join(testdir, '../erc20_approval_escrow/data/TransferApproval.json'), 'r') + self.abi_wallet = json.load(f) + f.close() + + backend = eth_tester.PyEVMBackend(eth_params) + self.eth_tester = eth_tester.EthereumTester(backend) + provider = web3.Web3.EthereumTesterProvider(self.eth_tester) + self.w3 = web3.Web3(provider) + c = self.w3.eth.contract(abi=self.abi_wallet, bytecode=bytecode) + tx_hash = c.constructor().transact({'from': self.w3.eth.accounts[0]}) + + r = self.w3.eth.getTransactionReceipt(tx_hash) + + self.address_wallet = r.contractAddress + + + f = open(os.path.join(testdir, '../erc20_approval_escrow/data/GiftableToken.bin'), 'r') + bytecode = f.read() + f.close() + + f = open(os.path.join(testdir, '../erc20_approval_escrow/data/GiftableToken.json'), 'r') + self.abi_token = json.load(f) + f.close() + + c = self.w3.eth.contract(abi=self.abi_token, bytecode=bytecode) + tx_hash = c.constructor('Foo Token', 'FOO', 18).transact({'from': self.w3.eth.accounts[0]}) + + r = self.w3.eth.getTransactionReceipt(tx_hash) + + self.address_token = r.contractAddress + c = self.w3.eth.contract(abi=self.abi_token, address=self.address_token) + + tx_hash = c.functions.mint(1000).transact({'from': self.w3.eth.accounts[0]}) + tx_hash = c.functions.transfer(self.w3.eth.accounts[1], 100).transact({'from': self.w3.eth.accounts[0]}) + tx_hash = c.functions.transfer(self.w3.eth.accounts[2], 100).transact({'from': self.w3.eth.accounts[0]}) + tx_hash = c.functions.transfer(self.w3.eth.accounts[4], 100).transact({'from': self.w3.eth.accounts[0]}) + + + def tearDown(self): + pass + + diff --git a/python/tests/test_app.py b/python/tests/test_app.py @@ -38,7 +38,7 @@ class Test(unittest.TestCase): provider = web3.Web3.EthereumTesterProvider(self.eth_tester) self.w3 = web3.Web3(provider) c = self.w3.eth.contract(abi=self.abi_wallet, bytecode=bytecode) - tx_hash = c.constructor([self.w3.eth.accounts[0]]).transact({'from': self.w3.eth.accounts[0]}) + tx_hash = c.constructor().transact({'from': self.w3.eth.accounts[0]}) r = self.w3.eth.getTransactionReceipt(tx_hash) @@ -71,12 +71,14 @@ class Test(unittest.TestCase): pass + @unittest.skip('foo') def test_basic(self): c = self.w3.eth.contract(abi=self.abi_wallet, address=self.address_wallet) - self.assertTrue(c.functions.approvers(self.w3.eth.accounts[0]).call()) - self.assertFalse(c.functions.approvers(self.w3.eth.accounts[1]).call()) - + self.assertTrue(c.functions.signers(self.w3.eth.accounts[0]).call()) + self.assertFalse(c.functions.signers(self.w3.eth.accounts[1]).call()) + + @unittest.skip('foo') def test_get(self): w = self.w3.eth.contract(abi=self.abi_wallet, address=self.address_wallet) t = self.w3.eth.contract(abi=self.abi_token, address=self.address_token) @@ -107,6 +109,7 @@ class Test(unittest.TestCase): + @unittest.skip('foo') def test_approval_missing(self): w = self.w3.eth.contract(abi=self.abi_wallet, address=self.address_wallet) t = self.w3.eth.contract(abi=self.abi_token, address=self.address_token) @@ -124,6 +127,7 @@ class Test(unittest.TestCase): w.functions.execute(serial).transact({'from': self.w3.eth.accounts[0]}) + @unittest.skip('foo') def test_approval(self): w = self.w3.eth.contract(abi=self.abi_wallet, address=self.address_wallet) t = self.w3.eth.contract(abi=self.abi_token, address=self.address_token) @@ -151,6 +155,7 @@ class Test(unittest.TestCase): self.assertEqual(t.functions.balanceOf(self.w3.eth.accounts[3]).call(), 10) + @unittest.skip('foo') def test_rejection(self): w = self.w3.eth.contract(abi=self.abi_wallet, address=self.address_wallet) t = self.w3.eth.contract(abi=self.abi_token, address=self.address_token) @@ -175,6 +180,7 @@ class Test(unittest.TestCase): self.assertEqual(t.functions.allowances(self.w3.eth.accounts[2], w.address).call(), 0) + @unittest.skip('foo') def test_indexes(self): w = self.w3.eth.contract(abi=self.abi_wallet, address=self.address_wallet) t = self.w3.eth.contract(abi=self.abi_token, address=self.address_token) @@ -193,6 +199,8 @@ class Test(unittest.TestCase): assert w.functions.getSerialAt(1).call() == 3 assert w.functions.getSerialAt(2).call() == 5 + + @unittest.skip('foo') def test_index_after_removal(self): w = self.w3.eth.contract(abi=self.abi_wallet, address=self.address_wallet) t = self.w3.eth.contract(abi=self.abi_token, address=self.address_token) diff --git a/python/tests/test_quorum.py b/python/tests/test_quorum.py @@ -0,0 +1,90 @@ +# standard imports +import logging +import unittest + +# testutil imports +from tests.base import TestBase + +logg = logging.getLogger() + + +class ERC20TransferAuthorizationQuorumTest(TestBase): + + @unittest.skip('wip') + def test_minimal_quorum(self): + w = self.w3.eth.contract(abi=self.abi_wallet, address=self.address_wallet) + t = self.w3.eth.contract(abi=self.abi_token, address=self.address_token) + + t.functions.approve(w.address, 10).transact({'from': self.w3.eth.accounts[2]}) + self.eth_tester.mine_block() + + tx_hash = w.functions.createRequest(self.w3.eth.accounts[3], t.address, 10).transact({'from': self.w3.eth.accounts[2]}) + r = self.w3.eth.getTransactionReceipt(tx_hash) + + topic_match = 'b609ae609609ee99268d05bc1371102cafe8d6b964bf082439ab16be2a01c87c' + log = r.logs[0] + topic = log.topics[0] + self.assertEqual(topic.hex()[2:], topic_match) + serial = int(log.data[66:], 16) + logg.debug('mined with serial {}'.format(serial)) + + with self.assertRaises(Exception): + w.functions.executeRequest(serial).transact({'from': self.w3.eth.accounts[0]}) + + tx_hashh = w.functions.yay(serial).transact({'from': self.w3.eth.accounts[0]}) + r = self.w3.eth.getTransactionReceipt(tx_hashh) + + topic_match = 'bcf6a68a2f901be4a23a41b53acd7697893a7e34def4e28acba584da75283b67' # Executed(serial) + log = r.logs[2] + topic = log.topics[0].hex()[2:] + logg.debug('topic {}'.format(topic)) + self.assertEqual(topic, topic_match) + + self.assertEqual(t.functions.balanceOf(self.w3.eth.accounts[2]).call(), 90) + self.assertEqual(t.functions.balanceOf(self.w3.eth.accounts[3]).call(), 10) + + + def test_simple_quorum(self): + w = self.w3.eth.contract(abi=self.abi_wallet, address=self.address_wallet) + t = self.w3.eth.contract(abi=self.abi_token, address=self.address_token) + + t.functions.approve(w.address, 10).transact({'from': self.w3.eth.accounts[2]}) + self.eth_tester.mine_block() + + w.functions.addSigner(self.w3.eth.accounts[5]).transact({'from': self.w3.eth.accounts[0]}) + w.functions.addSigner(self.w3.eth.accounts[6]).transact({'from': self.w3.eth.accounts[0]}) + w.functions.setThresholds(2, 0).transact({'from': self.w3.eth.accounts[0]}) + + tx_hash = w.functions.createRequest(self.w3.eth.accounts[3], t.address, 10).transact({'from': self.w3.eth.accounts[2]}) + r = self.w3.eth.getTransactionReceipt(tx_hash) + + topic_match = 'b609ae609609ee99268d05bc1371102cafe8d6b964bf082439ab16be2a01c87c' + log = r.logs[0] + topic = log.topics[0] + self.assertEqual(topic.hex()[2:], topic_match) + serial = int(log.data[66:], 16) + logg.debug('mined with serial {}'.format(serial)) + + tx_hashh = w.functions.yay(serial).transact({'from': self.w3.eth.accounts[0]}) + r = self.w3.eth.getTransactionReceipt(tx_hashh) + self.assertEqual(len(r.logs), 0) + + # attempt to execute fails + with self.assertRaises(Exception): + w.functions.executeRequest(serial).transact({'from': self.w3.eth.accounts[0]}) + + # verify we cannot vote twice + with self.assertRaises(Exception): + w.functions.yay(serial).transact({'from': self.w3.eth.accounts[0]}) + + # dough is still there + self.assertEqual(t.functions.balanceOf(self.w3.eth.accounts[2]).call(), 100) + + w.functions.yay(serial).transact({'from': self.w3.eth.accounts[5]}) + + self.assertEqual(t.functions.balanceOf(self.w3.eth.accounts[2]).call(), 90) + self.assertEqual(t.functions.balanceOf(self.w3.eth.accounts[3]).call(), 10) + + +if __name__ == '__main__': + unittest.main() diff --git a/solidity/TransferApproval.bin b/solidity/TransferApproval.bin @@ -1 +1 @@ -60806040523480156200001157600080fd5b50604051620016e1380380620016e18339818101604052810190620000379190620001c3565b60005b8151811015620000f35760016004600084848151811062000084577f4e487b7100000000000000000000000000000000000000000000000000000000600052603260045260246000fd5b602002602001015173ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060006101000a81548160ff0219169083151502179055508080620000ea90620002a9565b9150506200003a565b50600180819055506001600281905550506200036f565b6000620001216200011b846200023c565b62000208565b905080838252602082019050828560208602820111156200014157600080fd5b60005b858110156200017557816200015a88826200017f565b84526020840193506020830192505060018101905062000144565b5050509392505050565b600081519050620001908162000355565b92915050565b600082601f830112620001a857600080fd5b8151620001ba8482602086016200010a565b91505092915050565b600060208284031215620001d657600080fd5b600082015167ffffffffffffffff811115620001f157600080fd5b620001ff8482850162000196565b91505092915050565b6000604051905081810181811067ffffffffffffffff8211171562000232576200023162000326565b5b8060405250919050565b600067ffffffffffffffff8211156200025a576200025962000326565b5b602082029050602081019050919050565b600062000278826200027f565b9050919050565b600073ffffffffffffffffffffffffffffffffffffffff82169050919050565b6000819050919050565b6000620002b6826200029f565b91507fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff821415620002ec57620002eb620002f7565b5b600182019050919050565b7f4e487b7100000000000000000000000000000000000000000000000000000000600052601160045260246000fd5b7f4e487b7100000000000000000000000000000000000000000000000000000000600052604160045260246000fd5b62000360816200026b565b81146200036c57600080fd5b50565b611362806200037f6000396000f3fe608060405234801561001057600080fd5b50600436106100935760003560e01c806357ec347a1161006657806357ec347a146101345780636e417c691461015257806381d12c5814610182578063b0addede146101b6578063bac911ac146101e657610093565b806306661abd1461009857806308ae6377146100b65780630a144391146100d45780632d7788db14610104575b600080fd5b6100a0610216565b6040516100ad91906110ef565b60405180910390f35b6100be61021c565b6040516100cb91906110ef565b60405180910390f35b6100ee60048036038101906100e99190610ec7565b610247565b6040516100fb9190611094565b60405180910390f35b61011e60048036038101906101199190610f3f565b610267565b60405161012b9190611094565b60405180910390f35b61013c610553565b60405161014991906110ef565b60405180910390f35b61016c60048036038101906101679190610f3f565b610568565b6040516101799190611094565b60405180910390f35b61019c60048036038101906101979190610f3f565b610855565b6040516101ad95949392919061110a565b60405180910390f35b6101d060048036038101906101cb9190610ef0565b6108eb565b6040516101dd91906110ef565b60405180910390f35b61020060048036038101906101fb9190610f3f565b610b85565b60405161020d91906110ef565b60405180910390f35b60035481565b60008060025460015461022f91906111ad565b141561023e5760009050610244565b60025490505b90565b60046020528060005260406000206000915054906101000a900460ff1681565b6000600460003373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060009054906101000a900460ff166102f5576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004016102ec906110af565b60405180910390fd5b6000806000848152602001908152602001600020905082816000015414610351576040517f08c379a0000000000000000000000000000000000000000000000000000000008152600401610348906110cf565b60405180910390fd5b6000808260030160009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168360010160009054906101000a900473ffffffffffffffffffffffffffffffffffffffff168460010160009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1685600401546040516024016103f09392919061105d565b6040516020818303038152906040527f23b872dd000000000000000000000000000000000000000000000000000000007bffffffffffffffffffffffffffffffffffffffffffffffffffffffff19166020820180517bffffffffffffffffffffffffffffffffffffffffffffffffffffffff838183161783525050505060405161047a9190611046565b6000604051808303816000865af19150503d80600081146104b7576040519150601f19603f3d011682016040523d82523d6000602084013e6104bc565b606091505b50915091506104ce8360000154610d24565b8115610510577f607c56ea76669e46679e89091227c1a3f91841a4cf7588d5a6c84555fb59fdfd8560405161050391906110ef565b60405180910390a1610548565b7fdab20a0fcd702cf875c2d715d5c3fc99af66a716c94b3405408c94b7311c99eb8560405161053f91906110ef565b60405180910390a15b819350505050919050565b60006001805461056391906111ad565b905090565b6000600460003373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060009054906101000a900460ff166105f6576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004016105ed906110af565b60405180910390fd5b600080600084815260200190815260200160002090506000816000015411610653576040517f08c379a000000000000000000000000000000000000000000000000000000000815260040161064a906110cf565b60405180910390fd5b6000808260030160009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168360010160009054906101000a900473ffffffffffffffffffffffffffffffffffffffff168460020160009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1685600401546040516024016106f29392919061105d565b6040516020818303038152906040527f23b872dd000000000000000000000000000000000000000000000000000000007bffffffffffffffffffffffffffffffffffffffffffffffffffffffff19166020820180517bffffffffffffffffffffffffffffffffffffffffffffffffffffffff838183161783525050505060405161077c9190611046565b6000604051808303816000865af19150503d80600081146107b9576040519150601f19603f3d011682016040523d82523d6000602084013e6107be565b606091505b50915091506107d08360000154610d24565b8115610812577f607c56ea76669e46679e89091227c1a3f91841a4cf7588d5a6c84555fb59fdfd8560405161080591906110ef565b60405180910390a161084a565b7fdab20a0fcd702cf875c2d715d5c3fc99af66a716c94b3405408c94b7311c99eb8560405161084191906110ef565b60405180910390a15b819350505050919050565b60006020528060005260406000206000915090508060000154908060010160009054906101000a900473ffffffffffffffffffffffffffffffffffffffff16908060020160009054906101000a900473ffffffffffffffffffffffffffffffffffffffff16908060030160009054906101000a900473ffffffffffffffffffffffffffffffffffffffff16908060040154905085565b60006108f5610e2c565b60015481600001818152505084816040019073ffffffffffffffffffffffffffffffffffffffff16908173ffffffffffffffffffffffffffffffffffffffff168152505033816020019073ffffffffffffffffffffffffffffffffffffffff16908173ffffffffffffffffffffffffffffffffffffffff168152505083816060019073ffffffffffffffffffffffffffffffffffffffff16908173ffffffffffffffffffffffffffffffffffffffff1681525050828160800181815250508060008060015481526020019081526020016000206000820151816000015560208201518160010160006101000a81548173ffffffffffffffffffffffffffffffffffffffff021916908373ffffffffffffffffffffffffffffffffffffffff16021790555060408201518160020160006101000a81548173ffffffffffffffffffffffffffffffffffffffff021916908373ffffffffffffffffffffffffffffffffffffffff16021790555060608201518160030160006101000a81548173ffffffffffffffffffffffffffffffffffffffff021916908373ffffffffffffffffffffffffffffffffffffffff1602179055506080820151816004015590505060036000815480929190610ac790611286565b919050555060016000815480929190610adf90611286565b9190505550806060015173ffffffffffffffffffffffffffffffffffffffff16816040015173ffffffffffffffffffffffffffffffffffffffff16826020015173ffffffffffffffffffffffffffffffffffffffff167fb609ae609609ee99268d05bc1371102cafe8d6b964bf082439ab16be2a01c87c84608001518560000151604051610b6e92919061115d565b60405180910390a480600001519150509392505050565b600080600060025490505b600154811015610d185760008060008381526020019081526020016000206040518060a0016040529081600082015481526020016001820160009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1681526020016002820160009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1681526020016003820160009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1681526020016004820154815250509050600081600001511115610d045784831415610cf55780600001519350505050610d1f565b8280610d0090611286565b9350505b508080610d1090611286565b915050610b90565b5060009150505b919050565b6000808281526020019081526020016000206000808201600090556001820160006101000a81549073ffffffffffffffffffffffffffffffffffffffff02191690556002820160006101000a81549073ffffffffffffffffffffffffffffffffffffffff02191690556003820160006101000a81549073ffffffffffffffffffffffffffffffffffffffff02191690556004820160009055505060036000815480929190610dd19061125c565b919050555060006003541115610e1f57600254811415610e1a576000610df76000610b85565b90506000811415610e1057600154600281905550610e18565b806002819055505b505b610e29565b6001546002819055505b50565b6040518060a0016040528060008152602001600073ffffffffffffffffffffffffffffffffffffffff168152602001600073ffffffffffffffffffffffffffffffffffffffff168152602001600073ffffffffffffffffffffffffffffffffffffffff168152602001600081525090565b600081359050610eac816112fe565b92915050565b600081359050610ec181611315565b92915050565b600060208284031215610ed957600080fd5b6000610ee784828501610e9d565b91505092915050565b600080600060608486031215610f0557600080fd5b6000610f1386828701610e9d565b9350506020610f2486828701610e9d565b9250506040610f3586828701610eb2565b9150509250925092565b600060208284031215610f5157600080fd5b6000610f5f84828501610eb2565b91505092915050565b610f71816111e1565b82525050565b610f80816111f3565b82525050565b6000610f9182611186565b610f9b8185611191565b9350610fab818560208601611229565b80840191505092915050565b6000610fc4600d8361119c565b91507f4552525f4e4f5f414343455353000000000000000000000000000000000000006000830152602082019050919050565b600061100460138361119c565b91507f4552525f494e56414c49445f52455155455354000000000000000000000000006000830152602082019050919050565b6110408161121f565b82525050565b60006110528284610f86565b915081905092915050565b60006060820190506110726000830186610f68565b61107f6020830185610f68565b61108c6040830184611037565b949350505050565b60006020820190506110a96000830184610f77565b92915050565b600060208201905081810360008301526110c881610fb7565b9050919050565b600060208201905081810360008301526110e881610ff7565b9050919050565b60006020820190506111046000830184611037565b92915050565b600060a08201905061111f6000830188611037565b61112c6020830187610f68565b6111396040830186610f68565b6111466060830185610f68565b6111536080830184611037565b9695505050505050565b60006040820190506111726000830185611037565b61117f6020830184611037565b9392505050565b600081519050919050565b600081905092915050565b600082825260208201905092915050565b60006111b88261121f565b91506111c38361121f565b9250828210156111d6576111d56112cf565b5b828203905092915050565b60006111ec826111ff565b9050919050565b60008115159050919050565b600073ffffffffffffffffffffffffffffffffffffffff82169050919050565b6000819050919050565b60005b8381101561124757808201518184015260208101905061122c565b83811115611256576000848401525b50505050565b60006112678261121f565b9150600082141561127b5761127a6112cf565b5b600182039050919050565b60006112918261121f565b91507fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff8214156112c4576112c36112cf565b5b600182019050919050565b7f4e487b7100000000000000000000000000000000000000000000000000000000600052601160045260246000fd5b611307816111e1565b811461131257600080fd5b50565b61131e8161121f565b811461132957600080fd5b5056fea2646970667358221220334bc774a46af5bb91c82b6abec3cf6a0abab29376b9f3e605be99d2965f131564736f6c63430008000033 -\ No newline at end of file +60806040523480156200001157600080fd5b5033600160006101000a81548173ffffffffffffffffffffffffffffffffffffffff021916908373ffffffffffffffffffffffffffffffffffffffff16021790555060016003819055506001600481905550600160068190555060016008819055506200008760016000620000a060201b60201c565b5062000099336200012b60201b60201c565b50620003d2565b6000600854831115620000b257600080fd5b60008311620000c057600080fd5b600854821115620000d057600080fd5b82600681905550816007819055507f9f40cfd22fe91777c78f252bd21a710f3fb007dc2f321876891e7644ba0ae1756006546007546008546040516200011993929190620002da565b60405180910390a16001905092915050565b6000600160009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff163373ffffffffffffffffffffffffffffffffffffffff16146200018857600080fd5b60001515600960008473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060009054906101000a900460ff16151514620001e657600080fd5b6001600960008473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060006101000a81548160ff02191690831515021790555060086000815480929190620002539062000355565b91905055507f47d1c22a25bb3a5d4e481b9b1e6944c2eade3181a0a20b495ed61d35b5323f2482604051620002899190620002bd565b60405180910390a16008549050919050565b620002a68162000317565b82525050565b620002b7816200034b565b82525050565b6000602082019050620002d460008301846200029b565b92915050565b6000606082019050620002f16000830186620002ac565b620003006020830185620002ac565b6200030f6040830184620002ac565b949350505050565b600062000324826200032b565b9050919050565b600073ffffffffffffffffffffffffffffffffffffffff82169050919050565b6000819050919050565b600062000362826200034b565b91507fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff821415620003985762000397620003a3565b5b600182019050919050565b7f4e487b7100000000000000000000000000000000000000000000000000000000600052601160045260246000fd5b611ae280620003e26000396000f3fe608060405234801561001057600080fd5b50600436106101005760003560e01c80636e417c6911610097578063b0addede11610066578063b0addede146102e2578063bac911ac14610312578063e3064a7714610342578063eb12d61e1461037257610100565b80636e417c691461022b578063736c0d5b1461025b57806381d12c581461028b5780638da5cb5b146102c457610100565b80634797569a116100d35780634797569a1461018f57806357ec347a146101bf57806358d71f82146101dd578063614f427f1461020d57610100565b806306661abd1461010557806308ae6377146101235780630e316ab7146101415780631703a01814610171575b600080fd5b61010d6103a2565b60405161011a91906117e2565b60405180910390f35b61012b6103a8565b60405161013891906117e2565b60405180910390f35b61015b60048036038101906101569190611554565b6103d3565b60405161016891906117e2565b60405180910390f35b6101796105ce565b60405161018691906117e2565b60405180910390f35b6101a960048036038101906101a491906115cc565b6105d4565b6040516101b691906117e2565b60405180910390f35b6101c761083e565b6040516101d491906117e2565b60405180910390f35b6101f760048036038101906101f291906115cc565b610854565b60405161020491906117e2565b60405180910390f35b610215610a0c565b60405161022291906117e2565b60405180910390f35b610245600480360381019061024091906115cc565b610a12565b6040516102529190611787565b60405180910390f35b61027560048036038101906102709190611554565b610ceb565b6040516102829190611787565b60405180910390f35b6102a560048036038101906102a091906115cc565b610d0b565b6040516102bb9a999897969594939291906117fd565b60405180910390f35b6102cc610dcc565b6040516102d99190611735565b60405180910390f35b6102fc60048036038101906102f7919061157d565b610df2565b60405161030991906117e2565b60405180910390f35b61032c600480360381019061032791906115cc565b6110e7565b60405161033991906117e2565b60405180910390f35b61035c600480360381019061035791906115f5565b611166565b6040516103699190611787565b60405180910390f35b61038c60048036038101906103879190611554565b6111ec565b60405161039991906117e2565b60405180910390f35b60055481565b6000806004546003546103bb9190611920565b14156103ca57600090506103d0565b60045490505b90565b6000600160009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168273ffffffffffffffffffffffffffffffffffffffff16141561043057600080fd5b600160009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff163373ffffffffffffffffffffffffffffffffffffffff1614806104b757508173ffffffffffffffffffffffffffffffffffffffff163373ffffffffffffffffffffffffffffffffffffffff16145b6104c057600080fd5b60011515600960008473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060009054906101000a900460ff1615151461051d57600080fd5b6000600960008473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060006101000a81548160ff02191690831515021790555060086000815480929190610588906119dc565b91905055507f3525e22824a8a7df2c9a6029941c824cf95b6447f1e13d5128fd3826d35afe8b826040516105bc9190611735565b60405180910390a16008549050919050565b60065481565b60008060026000848152602001908152602001600020905060008160090160009054906101000a900460000b60000b1461060d57600080fd5b600080600085815260200190815260200160002060003373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060009054906101000a900460000b60000b1461067957600080fd5b600160008085815260200190815260200160002060003373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060006101000a81548160ff021916908360000b60ff1602179055508060080160008154809291906106fa90611a06565b9190505550806005015481600801546008546107169190611920565b1415610798577fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff8160090160006101000a81548160ff021916908360000b60ff1602179055507f94064f919a02d0565c6790e0615fb4ba6cf1be1dd679f0161be914613a1b9bb58360405161078b91906117e2565b60405180910390a1610831565b600081600601541180156107b3575080600601548160080154145b15610830577fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff8160090160006101000a81548160ff021916908360000b60ff1602179055507f2ae00ba9813199478b6f22f0c9b606daa70f8efc319c8d2fa6af63f66ea317638360405161082791906117e2565b60405180910390a15b5b8060080154915050919050565b6000600160035461084f9190611920565b905090565b60008060026000848152602001908152602001600020905060008160090160009054906101000a900460000b60000b1461088d57600080fd5b600080600085815260200190815260200160002060003373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060009054906101000a900460000b60000b146108f957600080fd5b600160008085815260200190815260200160002060003373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060006101000a81548160ff021916908360000b60ff16021790555080600701600081548092919061097a90611a06565b9190505550806005015481600701546008546109969190611920565b14156109ff5760018160090160006101000a81548160ff021916908360000b60ff1602179055507f3ad93af63cb7967b23e4fb500b7d7d28b07516325dcf341f88bebf959d82c1cb836040516109ec91906117e2565b60405180910390a16109fd83610a12565b505b8060070154915050919050565b60075481565b6000806002600084815260200190815260200160002090506000816000015411610a71576040517f08c379a0000000000000000000000000000000000000000000000000000000008152600401610a68906117a2565b60405180910390fd5b60018160090160009054906101000a900460000b60000b14610ac8576040517f08c379a0000000000000000000000000000000000000000000000000000000008152600401610abf906117c2565b60405180910390fd5b60028160090160006101000a81548160ff021916908360000b60ff1602179055506000808260030160009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168360010160009054906101000a900473ffffffffffffffffffffffffffffffffffffffff168460020160009054906101000a900473ffffffffffffffffffffffffffffffffffffffff168560040154604051602401610b8893929190611750565b6040516020818303038152906040527f23b872dd000000000000000000000000000000000000000000000000000000007bffffffffffffffffffffffffffffffffffffffffffffffffffffffff19166020820180517bffffffffffffffffffffffffffffffffffffffffffffffffffffffff8381831617835250505050604051610c12919061171e565b6000604051808303816000865af19150503d8060008114610c4f576040519150601f19603f3d011682016040523d82523d6000602084013e610c54565b606091505b5091509150610c668360000154611356565b8115610ca8577fbcf6a68a2f901be4a23a41b53acd7697893a7e34def4e28acba584da75283b6785604051610c9b91906117e2565b60405180910390a1610ce0565b7fdab20a0fcd702cf875c2d715d5c3fc99af66a716c94b3405408c94b7311c99eb85604051610cd791906117e2565b60405180910390a15b819350505050919050565b60096020528060005260406000206000915054906101000a900460ff1681565b60026020528060005260406000206000915090508060000154908060010160009054906101000a900473ffffffffffffffffffffffffffffffffffffffff16908060020160009054906101000a900473ffffffffffffffffffffffffffffffffffffffff16908060030160009054906101000a900473ffffffffffffffffffffffffffffffffffffffff16908060040154908060050154908060060154908060070154908060080154908060090160009054906101000a900460000b90508a565b600160009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1681565b6000610dfc611493565b60035481600001818152505084816040019073ffffffffffffffffffffffffffffffffffffffff16908173ffffffffffffffffffffffffffffffffffffffff168152505033816020019073ffffffffffffffffffffffffffffffffffffffff16908173ffffffffffffffffffffffffffffffffffffffff168152505083816060019073ffffffffffffffffffffffffffffffffffffffff16908173ffffffffffffffffffffffffffffffffffffffff1681525050828160800181815250506006548160a0018181525050806002600060035481526020019081526020016000206000820151816000015560208201518160010160006101000a81548173ffffffffffffffffffffffffffffffffffffffff021916908373ffffffffffffffffffffffffffffffffffffffff16021790555060408201518160020160006101000a81548173ffffffffffffffffffffffffffffffffffffffff021916908373ffffffffffffffffffffffffffffffffffffffff16021790555060608201518160030160006101000a81548173ffffffffffffffffffffffffffffffffffffffff021916908373ffffffffffffffffffffffffffffffffffffffff1602179055506080820151816004015560a0820151816005015560c0820151816006015560e0820151816007015561010082015181600801556101208201518160090160006101000a81548160ff021916908360000b60ff1602179055509050506005600081548092919061102990611a06565b91905055506003600081548092919061104190611a06565b9190505550806060015173ffffffffffffffffffffffffffffffffffffffff16816040015173ffffffffffffffffffffffffffffffffffffffff16826020015173ffffffffffffffffffffffffffffffffffffffff167fb609ae609609ee99268d05bc1371102cafe8d6b964bf082439ab16be2a01c87c846080015185600001516040516110d0929190611899565b60405180910390a480600001519150509392505050565b600080600060045490505b60035481101561115a57600060026000838152602001908152602001600020905060008160000154111561114657848314156111375780600001549350505050611161565b828061114290611a06565b9350505b50808061115290611a06565b9150506110f2565b5060009150505b919050565b600060085483111561117757600080fd5b6000831161118457600080fd5b60085482111561119357600080fd5b82600681905550816007819055507f9f40cfd22fe91777c78f252bd21a710f3fb007dc2f321876891e7644ba0ae1756006546007546008546040516111da939291906118c2565b60405180910390a16001905092915050565b6000600160009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff163373ffffffffffffffffffffffffffffffffffffffff161461124857600080fd5b60001515600960008473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060009054906101000a900460ff161515146112a557600080fd5b6001600960008473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060006101000a81548160ff0219169083151502179055506008600081548092919061131090611a06565b91905055507f47d1c22a25bb3a5d4e481b9b1e6944c2eade3181a0a20b495ed61d35b5323f24826040516113449190611735565b60405180910390a16008549050919050565b600260008281526020019081526020016000206000808201600090556001820160006101000a81549073ffffffffffffffffffffffffffffffffffffffff02191690556002820160006101000a81549073ffffffffffffffffffffffffffffffffffffffff02191690556003820160006101000a81549073ffffffffffffffffffffffffffffffffffffffff0219169055600482016000905560058201600090556006820160009055600782016000905560088201600090556009820160006101000a81549060ff0219169055505060056000815480929190611438906119dc565b9190505550600060055411156114865760045481141561148157600061145e60006110e7565b905060008114156114775760035460048190555061147f565b806004819055505b505b611490565b6003546004819055505b50565b60405180610140016040528060008152602001600073ffffffffffffffffffffffffffffffffffffffff168152602001600073ffffffffffffffffffffffffffffffffffffffff168152602001600073ffffffffffffffffffffffffffffffffffffffff16815260200160008152602001600081526020016000815260200160008152602001600081526020016000800b81525090565b60008135905061153981611a7e565b92915050565b60008135905061154e81611a95565b92915050565b60006020828403121561156657600080fd5b60006115748482850161152a565b91505092915050565b60008060006060848603121561159257600080fd5b60006115a08682870161152a565b93505060206115b18682870161152a565b92505060406115c28682870161153f565b9150509250925092565b6000602082840312156115de57600080fd5b60006115ec8482850161153f565b91505092915050565b6000806040838503121561160857600080fd5b60006116168582860161153f565b92505060206116278582860161153f565b9150509250929050565b61163a81611954565b82525050565b61164981611966565b82525050565b600061165a826118f9565b6116648185611904565b93506116748185602086016119a9565b80840191505092915050565b61168981611972565b82525050565b600061169c60138361190f565b91507f4552525f494e56414c49445f52455155455354000000000000000000000000006000830152602082019050919050565b60006116dc60108361190f565b91507f4552525f4e4f545f454e444f52534544000000000000000000000000000000006000830152602082019050919050565b6117188161199f565b82525050565b600061172a828461164f565b915081905092915050565b600060208201905061174a6000830184611631565b92915050565b60006060820190506117656000830186611631565b6117726020830185611631565b61177f604083018461170f565b949350505050565b600060208201905061179c6000830184611640565b92915050565b600060208201905081810360008301526117bb8161168f565b9050919050565b600060208201905081810360008301526117db816116cf565b9050919050565b60006020820190506117f7600083018461170f565b92915050565b600061014082019050611813600083018d61170f565b611820602083018c611631565b61182d604083018b611631565b61183a606083018a611631565b611847608083018961170f565b61185460a083018861170f565b61186160c083018761170f565b61186e60e083018661170f565b61187c61010083018561170f565b61188a610120830184611680565b9b9a5050505050505050505050565b60006040820190506118ae600083018561170f565b6118bb602083018461170f565b9392505050565b60006060820190506118d7600083018661170f565b6118e4602083018561170f565b6118f1604083018461170f565b949350505050565b600081519050919050565b600081905092915050565b600082825260208201905092915050565b600061192b8261199f565b91506119368361199f565b92508282101561194957611948611a4f565b5b828203905092915050565b600061195f8261197f565b9050919050565b60008115159050919050565b60008160000b9050919050565b600073ffffffffffffffffffffffffffffffffffffffff82169050919050565b6000819050919050565b60005b838110156119c75780820151818401526020810190506119ac565b838111156119d6576000848401525b50505050565b60006119e78261199f565b915060008214156119fb576119fa611a4f565b5b600182039050919050565b6000611a118261199f565b91507fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff821415611a4457611a43611a4f565b5b600182019050919050565b7f4e487b7100000000000000000000000000000000000000000000000000000000600052601160045260246000fd5b611a8781611954565b8114611a9257600080fd5b50565b611a9e8161199f565b8114611aa957600080fd5b5056fea2646970667358221220bb3ffd404eab5da5b2ec1981c136a2879accb2c218a5a3d6bd9c9adcd5f8744e64736f6c63430008000033 +\ No newline at end of file diff --git a/solidity/TransferApproval.json b/solidity/TransferApproval.json @@ -1 +1 @@ -[{"inputs":[{"internalType":"address[]","name":"_approvers","type":"address[]"}],"stateMutability":"nonpayable","type":"constructor"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"uint256","name":"serial","type":"uint256"}],"name":"NewExecution","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"uint256","name":"serial","type":"uint256"}],"name":"NewRejection","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"_sender","type":"address"},{"indexed":true,"internalType":"address","name":"_recipient","type":"address"},{"indexed":true,"internalType":"address","name":"_token","type":"address"},{"indexed":false,"internalType":"uint256","name":"_value","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"_serial","type":"uint256"}],"name":"NewRequest","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"uint256","name":"serial","type":"uint256"}],"name":"TransferFail","type":"event"},{"inputs":[{"internalType":"address","name":"","type":"address"}],"name":"approvers","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"count","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"_recipient","type":"address"},{"internalType":"address","name":"_token","type":"address"},{"internalType":"uint256","name":"_value","type":"uint256"}],"name":"createRequest","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"_serial","type":"uint256"}],"name":"executeRequest","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"_idx","type":"uint256"}],"name":"getSerialAt","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"lastSerial","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"nextSerial","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"_serial","type":"uint256"}],"name":"rejectRequest","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"","type":"uint256"}],"name":"requests","outputs":[{"internalType":"uint256","name":"serial","type":"uint256"},{"internalType":"address","name":"sender","type":"address"},{"internalType":"address","name":"recipient","type":"address"},{"internalType":"address","name":"token","type":"address"},{"internalType":"uint256","name":"value","type":"uint256"}],"stateMutability":"view","type":"function"}] +[{"inputs":[],"stateMutability":"nonpayable","type":"constructor"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"uint256","name":"_serial","type":"uint256"}],"name":"Approved","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"uint256","name":"_serial","type":"uint256"}],"name":"Executed","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"_sender","type":"address"},{"indexed":true,"internalType":"address","name":"_recipient","type":"address"},{"indexed":true,"internalType":"address","name":"_token","type":"address"},{"indexed":false,"internalType":"uint256","name":"_value","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"_serial","type":"uint256"}],"name":"NewRequest","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"uint256","name":"_quorum","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"_vetoThreshold","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"_signerCount","type":"uint256"}],"name":"QuorumSet","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"uint256","name":"_serial","type":"uint256"}],"name":"Rejected","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"address","name":"_signer","type":"address"}],"name":"SignerAdded","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"address","name":"_signer","type":"address"}],"name":"SignerRemoved","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"uint256","name":"_serial","type":"uint256"}],"name":"TransferFail","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"uint256","name":"_serial","type":"uint256"}],"name":"Vetoed","type":"event"},{"inputs":[{"internalType":"address","name":"_signer","type":"address"}],"name":"addSigner","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"count","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"_recipient","type":"address"},{"internalType":"address","name":"_token","type":"address"},{"internalType":"uint256","name":"_value","type":"uint256"}],"name":"createRequest","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"_serial","type":"uint256"}],"name":"executeRequest","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"_idx","type":"uint256"}],"name":"getSerialAt","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"lastSerial","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"_serial","type":"uint256"}],"name":"nay","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"nextSerial","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"owner","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"quorum","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"_signer","type":"address"}],"name":"removeSigner","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"","type":"uint256"}],"name":"requests","outputs":[{"internalType":"uint256","name":"serial","type":"uint256"},{"internalType":"address","name":"sender","type":"address"},{"internalType":"address","name":"recipient","type":"address"},{"internalType":"address","name":"token","type":"address"},{"internalType":"uint256","name":"value","type":"uint256"},{"internalType":"uint256","name":"quorum","type":"uint256"},{"internalType":"uint256","name":"vetoThreshold","type":"uint256"},{"internalType":"uint256","name":"yay","type":"uint256"},{"internalType":"uint256","name":"nay","type":"uint256"},{"internalType":"int8","name":"result","type":"int8"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"_quorum","type":"uint256"},{"internalType":"uint256","name":"_vetoThreshold","type":"uint256"}],"name":"setThresholds","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"","type":"address"}],"name":"signers","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"vetoThreshold","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"_serial","type":"uint256"}],"name":"yay","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"nonpayable","type":"function"}] diff --git a/solidity/TransferApproval.sol b/solidity/TransferApproval.sol @@ -9,25 +9,75 @@ contract ERC20ApprovalEscrow { address recipient; address token; uint256 value; + uint256 quorum; + uint256 vetoThreshold; + uint256 yay; + uint256 nay; + int8 result; // -1 rejected/vetoed, 0 = voting, 1 = approved, 2 = completed } + + mapping ( uint256 => mapping ( address => int8 )) vote; + address public owner; mapping(uint256 => Transaction) public requests; uint256 hi; uint256 lo; uint256 public count; + uint256 public quorum; + uint256 public vetoThreshold; + uint256 signerCount; - mapping(address => bool) public approvers; + mapping(address => bool) public signers; event NewRequest(address indexed _sender, address indexed _recipient, address indexed _token, uint256 _value, uint256 _serial); - event NewExecution(uint256 serial); - event NewRejection(uint256 serial); - event TransferFail(uint256 serial); - - constructor(address[] memory _approvers) public { - for (uint i = 0; i < _approvers.length; i++) { - approvers[_approvers[i]] = true; - } + event Executed(uint256 _serial); + event TransferFail(uint256 _serial); + event QuorumSet(uint256 _quorum, uint256 _vetoThreshold, uint256 _signerCount); + event SignerAdded(address _signer); + event SignerRemoved(address _signer); + event Vetoed(uint256 _serial); + event Approved(uint256 _serial); + event Rejected(uint256 _serial); + + constructor() public { + owner = msg.sender; hi = 1; lo = 1; + quorum = 1; + signerCount = 1; + setThresholds(1, 0); + addSigner(msg.sender); + } + + function addSigner(address _signer) public returns (uint256) { + require(msg.sender == owner); + require(signers[_signer] == false); + + signers[_signer] = true; + signerCount++; + emit SignerAdded(_signer); + return signerCount; + } + + function removeSigner(address _signer) public returns (uint256) { + require(_signer != owner); + require(msg.sender == owner || msg.sender == _signer); + require(signers[_signer] == true); + + signers[_signer] = false; + signerCount--; + emit SignerRemoved(_signer); + return signerCount; + } + + function setThresholds(uint256 _quorum, uint256 _vetoThreshold) public returns (bool) { + require(_quorum <= signerCount); + require(_quorum > 0); + require(_vetoThreshold <= signerCount); + + quorum = _quorum; + vetoThreshold = _vetoThreshold; + emit QuorumSet(quorum, vetoThreshold, signerCount); + return true; } function createRequest(address _recipient, address _token, uint256 _value) public returns (uint256) { @@ -38,8 +88,10 @@ contract ERC20ApprovalEscrow { txx.sender = msg.sender; txx.token = _token; txx.value = _value; - + txx.quorum = quorum; + requests[hi] = txx; + count++; hi++; @@ -81,7 +133,7 @@ contract ERC20ApprovalEscrow { function getSerialAt(uint256 _idx) public view returns ( uint256 ) { uint256 i; for (uint256 j = lo; j < hi; j++) { - Transaction memory txx = requests[j]; + Transaction storage txx = requests[j]; if (txx.serial > 0) { if (i == _idx) { return txx.serial; @@ -92,37 +144,59 @@ contract ERC20ApprovalEscrow { return 0; } - function executeRequest(uint256 _serial) public returns (bool) { - require(approvers[msg.sender], 'ERR_NO_ACCESS'); + function yay(uint256 _serial) public returns (uint256) { + Transaction storage txx = requests[_serial]; + + require(txx.result == 0); + require(vote[_serial][msg.sender] == 0); + + vote[_serial][msg.sender] = 1; + txx.yay++; + if (signerCount - txx.yay == txx.quorum) { + txx.result = 1; + emit Approved(_serial); + executeRequest(_serial); + } + + return txx.yay; + } + + function nay(uint256 _serial) public returns (uint256) { Transaction storage txx = requests[_serial]; - require(txx.serial > 0, 'ERR_INVALID_REQUEST'); - (bool success, bytes memory _r) = txx.token.call(abi.encodeWithSignature("transferFrom(address,address,uint256)", txx.sender, txx.recipient, txx.value)); + require(txx.result == 0); + require(vote[_serial][msg.sender] == 0); - removeItem(txx.serial); + vote[_serial][msg.sender] = 1; + txx.nay++; - if (success) { - emit NewRejection(_serial); - } else { - emit TransferFail(_serial); + if (signerCount - txx.nay == txx.quorum) { + txx.result = -1; + emit Rejected(_serial); + } else if (txx.vetoThreshold > 0 && txx.nay == txx.vetoThreshold) { + txx.result = -1; + emit Vetoed(_serial); } - return success; + return txx.nay; } - function rejectRequest(uint256 _serial) public returns (bool) { - require(approvers[msg.sender], 'ERR_NO_ACCESS'); - + function executeRequest(uint256 _serial) public returns (bool) { Transaction storage txx = requests[_serial]; - require(txx.serial == _serial, 'ERR_INVALID_REQUEST'); - (bool success, bytes memory _r) = txx.token.call(abi.encodeWithSignature("transferFrom(address,address,uint256)", txx.sender, txx.sender, txx.value)); + //require(txx.serial > 0, 'ERR_INVALID_REQUEST'); + require(txx.serial > 0, 'ERR_INVALID_REQUEST'); + require(txx.result == 1, 'ERR_NOT_ENDORSED'); + + txx.result = 2; + + (bool success, bytes memory _r) = txx.token.call(abi.encodeWithSignature("transferFrom(address,address,uint256)", txx.sender, txx.recipient, txx.value)); removeItem(txx.serial); if (success) { - emit NewRejection(_serial); + emit Executed(_serial); } else { emit TransferFail(_serial); }