From 80177fac93f6e8b1c7e592bae3ef606417cb8338 Mon Sep 17 00:00:00 2001 From: martyall Date: Wed, 6 Sep 2023 22:09:15 -0700 Subject: [PATCH] remove unused live tests --- test/chanterelle/.gitignore | 10 - test/chanterelle/README.md | 11 - test/chanterelle/chanterelle.json | 21 -- test/chanterelle/contracts/ComplexStorage.sol | 31 -- test/chanterelle/contracts/Migrations.sol | 23 -- test/chanterelle/contracts/MockERC20.sol | 10 - test/chanterelle/contracts/Multifilter.sol | 16 - test/chanterelle/contracts/PayableTest.sol | 14 - .../chanterelle/contracts/SimpleErrorTest.sol | 13 - test/chanterelle/contracts/SimpleStorage.sol | 18 -- test/chanterelle/package.json | 25 -- test/chanterelle/packages.dhall | 9 - test/chanterelle/spago.dhall | 10 - test/chanterelle/src/Main.purs | 9 - test/web3/Main.purs | 22 +- .../Web3Spec/Live/Code/ComplexStorage.purs | 9 - test/web3/Web3Spec/Live/Code/MockERC20.purs | 9 - test/web3/Web3Spec/Live/Code/Multifilter.purs | 9 - test/web3/Web3Spec/Live/Code/PayableTest.purs | 9 - .../Web3Spec/Live/Code/SimpleErrorTest.purs | 9 - .../Web3Spec/Live/Code/SimpleStorage.purs | 9 - .../Web3Spec/Live/ComplexStorageSpec.purs | 76 ----- .../Live/Contract/ComplexStorage.purs | 170 ---------- .../Web3Spec/Live/Contract/MockERC20.purs | 55 ---- .../Web3Spec/Live/Contract/Multifilter.purs | 74 ----- .../Web3Spec/Live/Contract/PayableTest.purs | 42 --- .../Live/Contract/SimpleErrorTest.purs | 42 --- .../Web3Spec/Live/Contract/SimpleStorage.purs | 77 ----- test/web3/Web3Spec/Live/FilterSpec.purs | 303 ------------------ test/web3/Web3Spec/Live/MockERC20Spec.purs | 46 --- test/web3/Web3Spec/Live/MultifilterSpec.purs | 126 -------- test/web3/Web3Spec/Live/PayableTestSpec.purs | 61 ---- .../Web3Spec/Live/SimpleErrorTestSpec.purs | 44 --- .../web3/Web3Spec/Live/SimpleStorageSpec.purs | 45 --- 34 files changed, 2 insertions(+), 1455 deletions(-) delete mode 100644 test/chanterelle/.gitignore delete mode 100644 test/chanterelle/README.md delete mode 100644 test/chanterelle/chanterelle.json delete mode 100644 test/chanterelle/contracts/ComplexStorage.sol delete mode 100644 test/chanterelle/contracts/Migrations.sol delete mode 100644 test/chanterelle/contracts/MockERC20.sol delete mode 100644 test/chanterelle/contracts/Multifilter.sol delete mode 100644 test/chanterelle/contracts/PayableTest.sol delete mode 100644 test/chanterelle/contracts/SimpleErrorTest.sol delete mode 100644 test/chanterelle/contracts/SimpleStorage.sol delete mode 100644 test/chanterelle/package.json delete mode 100644 test/chanterelle/packages.dhall delete mode 100644 test/chanterelle/spago.dhall delete mode 100644 test/chanterelle/src/Main.purs delete mode 100644 test/web3/Web3Spec/Live/Code/ComplexStorage.purs delete mode 100644 test/web3/Web3Spec/Live/Code/MockERC20.purs delete mode 100644 test/web3/Web3Spec/Live/Code/Multifilter.purs delete mode 100644 test/web3/Web3Spec/Live/Code/PayableTest.purs delete mode 100644 test/web3/Web3Spec/Live/Code/SimpleErrorTest.purs delete mode 100644 test/web3/Web3Spec/Live/Code/SimpleStorage.purs delete mode 100644 test/web3/Web3Spec/Live/ComplexStorageSpec.purs delete mode 100644 test/web3/Web3Spec/Live/Contract/ComplexStorage.purs delete mode 100644 test/web3/Web3Spec/Live/Contract/MockERC20.purs delete mode 100644 test/web3/Web3Spec/Live/Contract/Multifilter.purs delete mode 100644 test/web3/Web3Spec/Live/Contract/PayableTest.purs delete mode 100644 test/web3/Web3Spec/Live/Contract/SimpleErrorTest.purs delete mode 100644 test/web3/Web3Spec/Live/Contract/SimpleStorage.purs delete mode 100644 test/web3/Web3Spec/Live/FilterSpec.purs delete mode 100644 test/web3/Web3Spec/Live/MockERC20Spec.purs delete mode 100644 test/web3/Web3Spec/Live/MultifilterSpec.purs delete mode 100644 test/web3/Web3Spec/Live/PayableTestSpec.purs delete mode 100644 test/web3/Web3Spec/Live/SimpleErrorTestSpec.purs delete mode 100644 test/web3/Web3Spec/Live/SimpleStorageSpec.purs diff --git a/test/chanterelle/.gitignore b/test/chanterelle/.gitignore deleted file mode 100644 index f3ae781b..00000000 --- a/test/chanterelle/.gitignore +++ /dev/null @@ -1,10 +0,0 @@ -*bower_components* -*node_modules* -.purs-* -.psc* -output/* -build/* -*.#* -.psc-package/* -src/Contracts/* -package-lock.json diff --git a/test/chanterelle/README.md b/test/chanterelle/README.md deleted file mode 100644 index 81e7b0f9..00000000 --- a/test/chanterelle/README.md +++ /dev/null @@ -1,11 +0,0 @@ -# Purescript-Web3-Tests - -This directory contains a [chanterelle](https://github.com/f-o-a-m/chanterelle) project used for generating the FFI and bytecode needed for the actual test suite, rooted in `../web3`. To avoid circular dependencies, we cannot actually use the chanterelle package in the test suite itself, only to compile and generate code -- we are currently checking in generated FFI. You can regenerate it or overwrite it by running - -```bash -> chanterelle build -``` - -in this directory. - -The downside of avoiding circular dependencies in this is setup that we have to handle deployments in the test suite itself. Currently this means that we have to manually copy paste deployment bytecode from the `solc` output into source files for these deployments. A consequence of this is that **if you change the contract code, you will need to manually re copy/paste the deployment bytecode into the appropriate file**. Hopefully we can fix this soon. \ No newline at end of file diff --git a/test/chanterelle/chanterelle.json b/test/chanterelle/chanterelle.json deleted file mode 100644 index 46e7cde9..00000000 --- a/test/chanterelle/chanterelle.json +++ /dev/null @@ -1,21 +0,0 @@ -{ - "name": "purescript-web3-tests", - "version": "0.0.1", - "artifacts-dir": "build/contracts", - "source-dir": "contracts", - "modules": [ "ComplexStorage" - , "SimpleStorage" - , "PayableTest" - , "MockERC20" - , "SimpleErrorTest" - , "Multifilter" - ], - "dependencies": [], - "solc-version": "0.15.17", - "solc-output-selection": [], - "purescript-generator": { - "output-path": "../web3", - "module-prefix": "Web3Spec.Live.Contract" - - } -} diff --git a/test/chanterelle/contracts/ComplexStorage.sol b/test/chanterelle/contracts/ComplexStorage.sol deleted file mode 100644 index 98c0ec6c..00000000 --- a/test/chanterelle/contracts/ComplexStorage.sol +++ /dev/null @@ -1,31 +0,0 @@ -pragma solidity ^0.5.17; - -contract ComplexStorage { - uint public uintVal; - int public intVal; - bool public boolVal; - int224 public int224Val; - bool[2] public boolVectorVal; - int[] public intListVal; - string public stringVal; - bytes16 public bytes16Val; - bytes2[4][] public bytes2VectorListVal; - - event ValsSet(uint a, int b, bool c, int224 d, bool[2] e, int[] f, string g, bytes16 h, bytes2[4][] i); - - function setValues(uint _uintVal, int _intVal, bool _boolVal, int224 _int224Val, bool[2] memory _boolVectorVal, int[] memory _intListVal, string memory _stringVal, bytes16 _bytes16Val, bytes2[4][] memory _bytes2VectorListVal) public { - uintVal = _uintVal; - intVal = _intVal; - boolVal = _boolVal; - int224Val = _int224Val; - boolVectorVal = _boolVectorVal; - intListVal = _intListVal; - stringVal = _stringVal; - bytes16Val = _bytes16Val; - bytes2VectorListVal = _bytes2VectorListVal; - - emit ValsSet(_uintVal, _intVal, _boolVal, _int224Val, _boolVectorVal, _intListVal, _stringVal, _bytes16Val, _bytes2VectorListVal); - } - -} - diff --git a/test/chanterelle/contracts/Migrations.sol b/test/chanterelle/contracts/Migrations.sol deleted file mode 100644 index 81df774c..00000000 --- a/test/chanterelle/contracts/Migrations.sol +++ /dev/null @@ -1,23 +0,0 @@ -pragma solidity ^0.5.17; - -contract Migrations { - address public owner; - uint public last_completed_migration; - - modifier restricted() { - if (msg.sender == owner) _; - } - - function Migrations() { - owner = msg.sender; - } - - function setCompleted(uint completed) restricted { - last_completed_migration = completed; - } - - function upgrade(address new_address) restricted { - Migrations upgraded = Migrations(new_address); - upgraded.setCompleted(last_completed_migration); - } -} diff --git a/test/chanterelle/contracts/MockERC20.sol b/test/chanterelle/contracts/MockERC20.sol deleted file mode 100644 index 90904497..00000000 --- a/test/chanterelle/contracts/MockERC20.sol +++ /dev/null @@ -1,10 +0,0 @@ -pragma solidity ^0.5.17; - -contract MockERC20 { - - event Transfer(address indexed to, address indexed from, uint amount); - - function transfer(address to, uint amount) public { - emit Transfer(to, msg.sender, amount); - } -} diff --git a/test/chanterelle/contracts/Multifilter.sol b/test/chanterelle/contracts/Multifilter.sol deleted file mode 100644 index a0953818..00000000 --- a/test/chanterelle/contracts/Multifilter.sol +++ /dev/null @@ -1,16 +0,0 @@ -pragma solidity ^0.5.17; - -contract Multifilter { - -event E1(uint value1); -event E2(uint value2); - -function fireE1(uint _value) public { - emit E1(_value); -} - -function fireE2(uint _value) public { - emit E2(_value); -} - -} diff --git a/test/chanterelle/contracts/PayableTest.sol b/test/chanterelle/contracts/PayableTest.sol deleted file mode 100644 index f592a179..00000000 --- a/test/chanterelle/contracts/PayableTest.sol +++ /dev/null @@ -1,14 +0,0 @@ -pragma solidity ^0.5.17; - -contract PayableTest { - - event Content(uint _paidContent); - - function seeContent() payable public returns(uint){ - if (msg.value == 1000000000000000000) { - emit Content(1); - } else { - emit Content(0); - } - } -} diff --git a/test/chanterelle/contracts/SimpleErrorTest.sol b/test/chanterelle/contracts/SimpleErrorTest.sol deleted file mode 100644 index b61696da..00000000 --- a/test/chanterelle/contracts/SimpleErrorTest.sol +++ /dev/null @@ -1,13 +0,0 @@ -pragma solidity ^0.5.17; - -contract SimpleErrorTest { - - mapping(uint => string) public table; - - string[] public names; - - function testBool(bool _arg) public pure returns(bool){ - return !_arg; - } - -} diff --git a/test/chanterelle/contracts/SimpleStorage.sol b/test/chanterelle/contracts/SimpleStorage.sol deleted file mode 100644 index 490c5488..00000000 --- a/test/chanterelle/contracts/SimpleStorage.sol +++ /dev/null @@ -1,18 +0,0 @@ -pragma solidity ^0.5.17; - -contract SimpleStorage { - uint public count; - - event CountSet(uint _count); - - event Deployed(uint _blockNumber); - - constructor() public { - emit Deployed(block.number); - } - - function setCount(uint _count) public { - count = _count; - emit CountSet(_count); - } -} diff --git a/test/chanterelle/package.json b/test/chanterelle/package.json deleted file mode 100644 index f3bc70cd..00000000 --- a/test/chanterelle/package.json +++ /dev/null @@ -1,25 +0,0 @@ -{ - "private": true, - "scripts": { - "build": "chanterelle build" - }, - "devDependencies": { - "chanterelle": "github:f-o-a-m/chanterelle", - "pulp": "^13.0.0", - "purescript": "^0.13.0", - "purescript-psa": "^0.7.3", - "spago": "^0.16.0" - }, - "dependencies": { - "bn.js": "^4.11.0", - "ethjs-provider-http": "^0.1.6", - "keccak": "^1.0.2", - "mkdirp": "^0.5.1", - "purescript": "^0.14.2", - "purescript-psa": "^0.8.2", - "rlp": "^2.0.0", - "secp256k1": "^3.0.1", - "solc": "^0.5", - "spago": "^0.20.3" - } -} diff --git a/test/chanterelle/packages.dhall b/test/chanterelle/packages.dhall deleted file mode 100644 index 1919fe74..00000000 --- a/test/chanterelle/packages.dhall +++ /dev/null @@ -1,9 +0,0 @@ -let upstream = - https://github.com/f-o-a-m/package-sets/raw/feaf98cc4ca1b39ad9ed04f10a473759cbc2114e/purs-0.15.7-web3.dhall - sha256:2d868539460c47c2bf5ecf4c6b68c3ea3162849f2da9cd3f263b740299448d8f - -let overrides = {=} - -let additions = {=} - -in upstream // overrides // additions diff --git a/test/chanterelle/spago.dhall b/test/chanterelle/spago.dhall deleted file mode 100644 index e9f28a01..00000000 --- a/test/chanterelle/spago.dhall +++ /dev/null @@ -1,10 +0,0 @@ -{- -Welcome to a Spago project! -You can edit this file as you like. --} -{ name = "web3-tests" -, dependencies = - [ "console", "effect", "psci-support", "prelude" ] -, packages = ./packages.dhall -, sources = [ "src/**/*.purs" ] -} diff --git a/test/chanterelle/src/Main.purs b/test/chanterelle/src/Main.purs deleted file mode 100644 index 8e8a8b76..00000000 --- a/test/chanterelle/src/Main.purs +++ /dev/null @@ -1,9 +0,0 @@ -module Main where - -import Prelude -import Effect (Effect) -import Effect.Console (log) - -main :: Effect Unit -main = do - log "🍝" diff --git a/test/web3/Main.purs b/test/web3/Main.purs index 6b07f8ca..b016bd70 100644 --- a/test/web3/Main.purs +++ b/test/web3/Main.purs @@ -8,24 +8,18 @@ import Effect (Effect) import Effect.Aff (Aff, Milliseconds(..), launchAff_) import Effect.Class (liftEffect) import Network.Ethereum.Web3.Types.Provider (httpProvider) -import Test.Spec (Spec, SpecT, parallel, mapSpecTree) +import Test.Spec (Spec, SpecT, mapSpecTree) import Test.Spec.Reporter.Console (consoleReporter) import Test.Spec.Runner (defaultConfig, runSpecT) import Web3Spec.Encoding.ContainersSpec as EncodingContainersSpec import Web3Spec.Encoding.DataSpec as EncodingDataSpec import Web3Spec.Encoding.GenericSpec as EncodingGenericSpec import Web3Spec.Encoding.SimpleSpec as EncodingSimpleSpec -import Web3Spec.Live.SimpleStorageSpec as SimpleStorageSpec -import Web3Spec.Live.ComplexStorageSpec as ComplexStorageSpec -import Web3Spec.Live.MockERC20Spec as MockERC20Spec -import Web3Spec.Live.PayableTestSpec as PayableTestSpec -import Web3Spec.Live.SimpleErrorTestSpec as SimpleErrorTestSpec -import Web3Spec.Live.MultifilterSpec as MultifilterSpec import Web3Spec.Live.RPCSpec as RPCSpec -import Web3Spec.Live.FilterSpec as FilterSpec import Web3Spec.Types.EtherUnitSpec as EtherUnitSpec import Web3Spec.Types.VectorSpec as VectorSpec + main :: Effect Unit main = launchAff_ do @@ -42,18 +36,6 @@ main = EncodingGenericSpec.spec EtherUnitSpec.spec RPCSpec.spec p - FilterSpec.spec p - -- payable spec can't be run in parallel :/ - PayableTestSpec.spec p - -- all of these tests only have one `it` statement and - -- are dealing with separate contracts so they can be run - -- in parallel - parallel do - SimpleStorageSpec.spec p - ComplexStorageSpec.spec p - MockERC20Spec.spec p - SimpleErrorTestSpec.spec p - MultifilterSpec.spec p where hoist :: Spec ~> SpecT Aff Unit Aff hoist = mapSpecTree (pure <<< un Identity) identity diff --git a/test/web3/Web3Spec/Live/Code/ComplexStorage.purs b/test/web3/Web3Spec/Live/Code/ComplexStorage.purs deleted file mode 100644 index 34e71d96..00000000 --- a/test/web3/Web3Spec/Live/Code/ComplexStorage.purs +++ /dev/null @@ -1,9 +0,0 @@ -module Web3Spec.Live.Code.ComplexStorage where - -import Network.Ethereum.Web3 (HexString) -import Web3Spec.Live.Utils (mkHexString') - -deployBytecode :: HexString -deployBytecode = - mkHexString' - "608060405234801561001057600080fd5b50610d69806100206000396000f3fe608060405234801561001057600080fd5b506004361061009e5760003560e01c80639a0283ed116100665780639a0283ed146104535780639d49a304146104715780639eb7a6b214610495578063c84a4100146104d9578063f4f67ad71461051f5761009e565b80631aadfbdb146100a35780632316afea1461034e578063579c738a1461037057806382a35c77146103f35780638ba27dca14610411575b600080fd5b61034c60048036036101408110156100ba57600080fd5b8101908080359060200190929190803590602001909291908035151590602001909291908035601b0b906020019092919080604001906002806020026040519081016040528092919082600260200280828437600081840152601f19601f82011690508083019250505050505091929192908035906020019064010000000081111561014557600080fd5b82018360208201111561015757600080fd5b8035906020019184602083028401116401000000008311171561017957600080fd5b919080806020026020016040519081016040528093929190818152602001838360200280828437600081840152601f19601f820116905080830192505050505050509192919290803590602001906401000000008111156101d957600080fd5b8201836020820111156101eb57600080fd5b8035906020019184600183028401116401000000008311171561020d57600080fd5b91908080601f016020809104026020016040519081016040528093929190818152602001838380828437600081840152601f19601f82011690508083019250505050505050919291929080356fffffffffffffffffffffffffffffffff191690602001909291908035906020019064010000000081111561028d57600080fd5b82018360208201111561029f57600080fd5b803590602001918460808302840111640100000000831117156102c157600080fd5b9190808060200260200160405190810160405280939291908181526020016000905b8282101561033a578484839050608002016004806020026040519081016040528092919082600460200280828437600081840152601f19601f820116905080830192505050505050815260200190600101906102e3565b505050505091929192905050506105ad565b005b61035661088c565b604051808215151515815260200191505060405180910390f35b61037861089f565b6040518080602001828103825283818151815260200191508051906020019080838360005b838110156103b857808201518184015260208101905061039d565b50505050905090810190601f1680156103e55780820380516001836020036101000a031916815260200191505b509250505060405180910390f35b6103fb61093d565b6040518082815260200191505060405180910390f35b61043d6004803603602081101561042757600080fd5b8101908080359060200190929190505050610943565b6040518082815260200191505060405180910390f35b61045b610964565b6040518082815260200191505060405180910390f35b61047961096a565b6040518082601b0b601b0b815260200191505060405180910390f35b61049d61097d565b60405180826fffffffffffffffffffffffffffffffff19166fffffffffffffffffffffffffffffffff1916815260200191505060405180910390f35b610505600480360360208110156104ef57600080fd5b8101908080359060200190929190505050610990565b604051808215151515815260200191505060405180910390f35b6105556004803603604081101561053557600080fd5b8101908080359060200190929190803590602001909291905050506109b7565b60405180827dffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff19167dffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff1916815260200191505060405180910390f35b886000819055508760018190555086600260006101000a81548160ff02191690831515021790555085600260016101000a8154817bffffffffffffffffffffffffffffffffffffffffffffffffffffffff0219169083601b0b7bffffffffffffffffffffffffffffffffffffffffffffffffffffffff16021790555084600390600261063a9291906109f9565b508360049080519060200190610651929190610a92565b508260059080519060200190610668929190610adf565b5081600660006101000a8154816fffffffffffffffffffffffffffffffff021916908360801c021790555080600790805190602001906106a9929190610b5f565b507f88d23351ad32a937b11ca10530404f8297d29803e94709336b48c1f82c15b3cc898989898989898989604051808a81526020018981526020018815151515815260200187601b0b601b0b815260200186600260200280838360005b83811015610721578082015181840152602081019050610706565b505050509050018060200180602001856fffffffffffffffffffffffffffffffff19166fffffffffffffffffffffffffffffffff1916815260200180602001848103845288818151815260200191508051906020019060200280838360005b8381101561079b578082015181840152602081019050610780565b50505050905001848103835287818151815260200191508051906020019080838360005b838110156107da5780820151818401526020810190506107bf565b50505050905090810190601f1680156108075780820380516001836020036101000a031916815260200191505b508481038252858181518152602001915080516000925b818410156108675782846020026020010151600460200280838360005b8381101561085657808201518184015260208101905061083b565b50505050905001926001019261081e565b925050509c5050505050505050505050505060405180910390a1505050505050505050565b600260009054906101000a900460ff1681565b60058054600181600116156101000203166002900480601f0160208091040260200160405190810160405280929190818152602001828054600181600116156101000203166002900480156109355780601f1061090a57610100808354040283529160200191610935565b820191906000526020600020905b81548152906001019060200180831161091857829003601f168201915b505050505081565b60015481565b6004818154811061095057fe5b906000526020600020016000915090505481565b60005481565b600260019054906101000a9004601b0b81565b600660009054906101000a900460801b81565b6003816002811061099d57fe5b60209182820401919006915054906101000a900460ff1681565b600782815481106109c457fe5b9060005260206000200181600481106109d957fe5b60109182820401919006600202915091509054906101000a900460f01b81565b826002601f01602090048101928215610a815791602002820160005b83821115610a5257835183826101000a81548160ff0219169083151502179055509260200192600101602081600001049283019260010302610a15565b8015610a7f5782816101000a81549060ff0219169055600101602081600001049283019260010302610a52565b505b509050610a8e9190610bba565b5090565b828054828255906000526020600020908101928215610ace579160200282015b82811115610acd578251825591602001919060010190610ab2565b5b509050610adb9190610bea565b5090565b828054600181600116156101000203166002900490600052602060002090601f016020900481019282601f10610b2057805160ff1916838001178555610b4e565b82800160010185558215610b4e579182015b82811115610b4d578251825591602001919060010190610b32565b5b509050610b5b9190610c0f565b5090565b828054828255906000526020600020908101928215610ba9579160200282015b82811115610ba857825182906004610b98929190610c34565b5091602001919060010190610b7f565b5b509050610bb69190610cd0565b5090565b610be791905b80821115610be357600081816101000a81549060ff021916905550600101610bc0565b5090565b90565b610c0c91905b80821115610c08576000816000905550600101610bf0565b5090565b90565b610c3191905b80821115610c2d576000816000905550600101610c15565b5090565b90565b826004600f01601090048101928215610cbf5791602002820160005b83821115610c8f57835183826101000a81548161ffff021916908360f01c02179055509260200192600201602081600101049283019260010302610c50565b8015610cbd5782816101000a81549061ffff0219169055600201602081600101049283019260010302610c8f565b505b509050610ccc9190610cfc565b5090565b610cf991905b80821115610cf55760008181610cec9190610d2d565b50600101610cd6565b5090565b90565b610d2a91905b80821115610d2657600081816101000a81549061ffff021916905550600101610d02565b5090565b90565b506000905556fea265627a7a723158203853a916101d8e3d01a082a6d71e4551cf200254517d8a5720ee4db8f3404f9164736f6c63430005110032" diff --git a/test/web3/Web3Spec/Live/Code/MockERC20.purs b/test/web3/Web3Spec/Live/Code/MockERC20.purs deleted file mode 100644 index a8880356..00000000 --- a/test/web3/Web3Spec/Live/Code/MockERC20.purs +++ /dev/null @@ -1,9 +0,0 @@ -module Web3Spec.Live.Code.MockERC20 where - -import Network.Ethereum.Web3 (HexString) -import Web3Spec.Live.Utils (mkHexString') - -deployBytecode :: HexString -deployBytecode = - mkHexString' - "608060405234801561001057600080fd5b50610116806100206000396000f3fe6080604052348015600f57600080fd5b506004361060285760003560e01c8063a9059cbb14602d575b600080fd5b607660048036036040811015604157600080fd5b81019080803573ffffffffffffffffffffffffffffffffffffffff169060200190929190803590602001909291905050506078565b005b3373ffffffffffffffffffffffffffffffffffffffff168273ffffffffffffffffffffffffffffffffffffffff167fddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef836040518082815260200191505060405180910390a3505056fea265627a7a723158208300a562056e4d08e97a1ee090626626f600a3640981be4eea6503056391d60e64736f6c63430005110032" diff --git a/test/web3/Web3Spec/Live/Code/Multifilter.purs b/test/web3/Web3Spec/Live/Code/Multifilter.purs deleted file mode 100644 index e5122791..00000000 --- a/test/web3/Web3Spec/Live/Code/Multifilter.purs +++ /dev/null @@ -1,9 +0,0 @@ -module Web3Spec.Live.Code.Multifilter where - -import Network.Ethereum.Web3 (HexString) -import Web3Spec.Live.Utils (mkHexString') - -deployBytecode :: HexString -deployBytecode = - mkHexString' - "608060405234801561001057600080fd5b50610140806100206000396000f3fe608060405234801561001057600080fd5b50600436106100365760003560e01c8063bf9670db1461003b578063e6a1a30814610069575b600080fd5b6100676004803603602081101561005157600080fd5b8101908080359060200190929190505050610097565b005b6100956004803603602081101561007f57600080fd5b81019080803590602001909291905050506100d1565b005b7f47e2689743f14e97f7dcfa5eec10ba1dff02f83b3d1d4b9c07b206cbbda66450816040518082815260200191505060405180910390a150565b7fa48a6b249a5084126c3da369fbc9b16827ead8cb5cdc094b717d3f1dcd995e29816040518082815260200191505060405180910390a15056fea265627a7a72315820bb4db7a08d867ead852463e6545a236cce4b7c7079472b01bbdbf569614337c064736f6c63430005110032" diff --git a/test/web3/Web3Spec/Live/Code/PayableTest.purs b/test/web3/Web3Spec/Live/Code/PayableTest.purs deleted file mode 100644 index e4676d9c..00000000 --- a/test/web3/Web3Spec/Live/Code/PayableTest.purs +++ /dev/null @@ -1,9 +0,0 @@ -module Web3Spec.Live.Code.PayableTest where - -import Network.Ethereum.Web3 (HexString) -import Web3Spec.Live.Utils (mkHexString') - -deployBytecode :: HexString -deployBytecode = - mkHexString' - "608060405234801561001057600080fd5b5060fb8061001f6000396000f3fe608060405260043610601c5760003560e01c8063b145d3f4146021575b600080fd5b6027603d565b6040518082815260200191505060405180910390f35b6000670de0b6b3a7640000341415608a577f78692973dbc680e9276487808ebf9b485db7b4fbb74c05799e397695b5c7686b60016040518082815260200191505060405180910390a160c3565b7f78692973dbc680e9276487808ebf9b485db7b4fbb74c05799e397695b5c7686b60006040518082815260200191505060405180910390a15b9056fea265627a7a72315820653b183cf9b306cae27a9663c54e4bcdef9a36b35b8b59263d734072499c3ce764736f6c63430005110032" diff --git a/test/web3/Web3Spec/Live/Code/SimpleErrorTest.purs b/test/web3/Web3Spec/Live/Code/SimpleErrorTest.purs deleted file mode 100644 index 5439c1b4..00000000 --- a/test/web3/Web3Spec/Live/Code/SimpleErrorTest.purs +++ /dev/null @@ -1,9 +0,0 @@ -module Web3Spec.Live.Code.SimpleErrorTest where - -import Network.Ethereum.Web3 (HexString) -import Web3Spec.Live.Utils (mkHexString') - -deployBytecode :: HexString -deployBytecode = - mkHexString' - "608060405234801561001057600080fd5b50610385806100206000396000f3fe608060405234801561001057600080fd5b50600436106100415760003560e01c80634622ab0314610046578063bafff8c0146100ed578063e8dde23214610194575b600080fd5b6100726004803603602081101561005c57600080fd5b81019080803590602001909291905050506101dc565b6040518080602001828103825283818151815260200191508051906020019080838360005b838110156100b2578082015181840152602081019050610097565b50505050905090810190601f1680156100df5780820380516001836020036101000a031916815260200191505b509250505060405180910390f35b6101196004803603602081101561010357600080fd5b8101908080359060200190929190505050610295565b6040518080602001828103825283818151815260200191508051906020019080838360005b8381101561015957808201518184015260208101905061013e565b50505050905090810190601f1680156101865780820380516001836020036101000a031916815260200191505b509250505060405180910390f35b6101c2600480360360208110156101aa57600080fd5b81019080803515159060200190929190505050610345565b604051808215151515815260200191505060405180910390f35b600181815481106101e957fe5b906000526020600020016000915090508054600181600116156101000203166002900480601f01602080910402602001604051908101604052809291908181526020018280546001816001161561010002031660029004801561028d5780601f106102625761010080835404028352916020019161028d565b820191906000526020600020905b81548152906001019060200180831161027057829003601f168201915b505050505081565b60006020528060005260406000206000915090508054600181600116156101000203166002900480601f01602080910402602001604051908101604052809291908181526020018280546001816001161561010002031660029004801561033d5780601f106103125761010080835404028352916020019161033d565b820191906000526020600020905b81548152906001019060200180831161032057829003601f168201915b505050505081565b60008115905091905056fea265627a7a72315820dab93eda565cb9057d5b1be8ec881b24251fc5d67e14beddc0563abcc710254164736f6c63430005110032" diff --git a/test/web3/Web3Spec/Live/Code/SimpleStorage.purs b/test/web3/Web3Spec/Live/Code/SimpleStorage.purs deleted file mode 100644 index 2e5efea6..00000000 --- a/test/web3/Web3Spec/Live/Code/SimpleStorage.purs +++ /dev/null @@ -1,9 +0,0 @@ -module Web3Spec.Live.Code.SimpleStorage where - -import Network.Ethereum.Web3 (HexString) -import Web3Spec.Live.Utils (mkHexString') - -deployBytecode :: HexString -deployBytecode = - mkHexString' - "608060405234801561001057600080fd5b507fb94ae47ec9f4248692e2ecf9740b67ab493f3dcc8452bedc7d9cd911c28d1ca5436040518082815260200191505060405180910390a160fa806100566000396000f3fe6080604052348015600f57600080fd5b506004361060325760003560e01c806306661abd146037578063d14e62b8146053575b600080fd5b603d607e565b6040518082815260200191505060405180910390f35b607c60048036036020811015606757600080fd5b81019080803590602001909291905050506084565b005b60005481565b806000819055507fa32bc18230dd172221ac5c4821a5f1f1a831f27b1396d244cdd891c58f132435816040518082815260200191505060405180910390a15056fea265627a7a72315820d7b31540fda8e9a40bad589e7f75581258f70add83315bbdfc2700a3d79df47e64736f6c63430005110032" diff --git a/test/web3/Web3Spec/Live/ComplexStorageSpec.purs b/test/web3/Web3Spec/Live/ComplexStorageSpec.purs deleted file mode 100644 index d2720dfd..00000000 --- a/test/web3/Web3Spec/Live/ComplexStorageSpec.purs +++ /dev/null @@ -1,76 +0,0 @@ -module Web3Spec.Live.ComplexStorageSpec (spec) where - -import Prelude -import Data.Lens ((?~)) -import Data.Tuple (Tuple(..)) -import Effect.Aff (Aff) -import Effect.Class.Console as C -import Network.Ethereum.Web3 (Provider, Value, Wei, _data, _from, _to, _value, mkValue, nilVector) -import Network.Ethereum.Web3.Api as Api -import Network.Ethereum.Web3.Solidity ((:<)) -import Network.Ethereum.Web3.Solidity.Sizes (s16, s2, s224, s256) -import Test.Spec (SpecT, beforeAll, describe, it) -import Test.Spec.Assertions (shouldEqual) -import Type.Proxy (Proxy(..)) -import Web3Spec.Live.Contract.ComplexStorage as ComplexStorage -import Web3Spec.Live.Code.ComplexStorage as ComplexStorageCode -import Web3Spec.Live.Utils (assertWeb3, defaultTestTxOptions, deployContract, mkBytesN, mkIntN, mkUIntN, takeEvent) - -spec :: Provider -> SpecT Aff Unit Aff Unit -spec provider = - describe "Complex Storage" - $ beforeAll - ( deployContract provider C.log "ComplexStorage" - $ \txOpts -> - Api.eth_sendTransaction $ txOpts # _data ?~ ComplexStorageCode.deployBytecode - # _value - ?~ (mkValue zero :: Value Wei) - ) - $ it "Can encode and decode complex objects to / from a smart contract" - $ \complexStorageCfg -> do - let - { contractAddress: complexStorageAddress, userAddress } = complexStorageCfg - - uint = mkUIntN s256 1 - - int = mkIntN s256 $ negate 1 - - bool = true - - int224 = mkIntN s224 221 - - bools = true :< false :< nilVector - - ints = map (mkIntN s256) [ 1, negate 1, 3 ] - - string = "hello" - - bytes16 = mkBytesN s16 "12345678123456781234567812345678" - - elem = mkBytesN s2 "1234" - - bytes2s = [ elem :< elem :< elem :< elem :< nilVector, elem :< elem :< elem :< elem :< nilVector ] - - txOptions = - defaultTestTxOptions # _from ?~ userAddress - # _to - ?~ complexStorageAddress - - arg = - { _uintVal: uint - , _intVal: int - , _boolVal: bool - , _int224Val: int224 - , _boolVectorVal: bools - , _intListVal: ints - , _stringVal: string - , _bytes16Val: bytes16 - , _bytes2VectorListVal: bytes2s - } - - setValsAction = ComplexStorage.setValues txOptions arg - pure unit - Tuple _ _event <- - assertWeb3 provider - $ takeEvent (Proxy :: Proxy ComplexStorage.ValsSet) complexStorageAddress setValsAction - _event `shouldEqual` ComplexStorage.ValsSet { a: uint, b: int, c: bool, d: int224, e: bools, f: ints, g: string, h: bytes16, i: bytes2s } diff --git a/test/web3/Web3Spec/Live/Contract/ComplexStorage.purs b/test/web3/Web3Spec/Live/Contract/ComplexStorage.purs deleted file mode 100644 index ca87cd3c..00000000 --- a/test/web3/Web3Spec/Live/Contract/ComplexStorage.purs +++ /dev/null @@ -1,170 +0,0 @@ -module Web3Spec.Live.Contract.ComplexStorage where - -import Prelude - -import Data.Either (Either) -import Data.Eq.Generic (genericEq) -import Data.Functor.Tagged (Tagged, tagged) -import Data.Generic.Rep (class Generic) -import Data.Lens (set) -import Data.Maybe (Maybe(..), fromJust) -import Data.Newtype (class Newtype) -import Data.Show.Generic (genericShow) -import Network.Ethereum.Web3 (Vector, class EventFilter, _address, _topics, call, sendTx) -import Network.Ethereum.Web3.Contract.Internal (uncurryFields) -import Network.Ethereum.Web3.Solidity (BytesN, IntN, UIntN, Tuple0(..), Tuple1(..), Tuple2(..), Tuple9(..), class IndexedEvent, unTuple1) -import Network.Ethereum.Web3.Types (CallError, ChainCursor, HexString, NoPay, TransactionOptions, Web3, defaultFilter, mkHexString) -import Partial.Unsafe (unsafePartial) - -newtype ValsSet = ValsSet - { a :: UIntN 256 - , b :: IntN 256 - , c :: Boolean - , d :: IntN 224 - , e :: Vector 2 Boolean - , f :: Array (IntN 256) - , g :: String - , h :: BytesN 16 - , i :: Array (Vector 4 (BytesN 2)) - } - -derive instance Newtype ValsSet _ -derive instance Generic ValsSet _ -instance Show ValsSet where - show = genericShow - -instance Eq ValsSet where - eq = genericEq - -instance EventFilter ValsSet where - eventFilter _ addr = defaultFilter # set _address (Just addr) # set _topics - ( Just - [ Just $ unsafePartial $ fromJust $ mkHexString - "88d23351ad32a937b11ca10530404f8297d29803e94709336b48c1f82c15b3cc" - ] - ) - -instance - IndexedEvent Tuple0 - ( Tuple9 (Tagged "a" (UIntN 256)) (Tagged "b" (IntN 256)) (Tagged "c" Boolean) - (Tagged "d" (IntN 224)) - (Tagged "e" (Vector 2 Boolean)) - (Tagged "f" (Array (IntN 256))) - (Tagged "g" String) - (Tagged "h" (BytesN 16)) - (Tagged "i" (Array (Vector 4 (BytesN 2)))) - ) - ValsSet where - isAnonymous _ = false - -type BoolValFn = Tagged "boolVal()" Tuple0 - -boolVal :: TransactionOptions NoPay -> ChainCursor -> Web3 (Either CallError Boolean) -boolVal x1 x2 = map unTuple1 <$> call x1 x2 (tagged Tuple0 :: BoolValFn) - -type BoolVectorValFn = Tagged "boolVectorVal(uint256)" (Tuple1 (UIntN 256)) - -boolVectorVal - :: TransactionOptions NoPay -> ChainCursor -> UIntN 256 -> Web3 (Either CallError Boolean) -boolVectorVal x1 x2 x3 = boolVectorVal' x1 x2 x3 - where - boolVectorVal' - :: TransactionOptions NoPay -> ChainCursor -> UIntN 256 -> Web3 (Either CallError Boolean) - boolVectorVal' _x1 _x2 _x3 = map unTuple1 <$> call _x1 _x2 - (tagged $ Tuple1 _x3 :: BoolVectorValFn) - -type Bytes16ValFn = Tagged "bytes16Val()" Tuple0 - -bytes16Val :: TransactionOptions NoPay -> ChainCursor -> Web3 (Either CallError (BytesN 16)) -bytes16Val x1 x2 = map unTuple1 <$> call x1 x2 (tagged Tuple0 :: Bytes16ValFn) - -type Bytes2VectorListValFn = Tagged "bytes2VectorListVal(uint256,uint256)" - (Tuple2 (UIntN 256) (UIntN 256)) - -bytes2VectorListVal - :: TransactionOptions NoPay - -> ChainCursor - -> UIntN 256 - -> UIntN 256 - -> Web3 (Either CallError (BytesN 2)) -bytes2VectorListVal x1 x2 x3 x4 = bytes2VectorListVal' x1 x2 x3 x4 - where - bytes2VectorListVal' - :: TransactionOptions NoPay - -> ChainCursor - -> UIntN 256 - -> UIntN 256 - -> Web3 (Either CallError (BytesN 2)) - bytes2VectorListVal' _x1 _x2 _x3 _x4 = map unTuple1 <$> call _x1 _x2 - (tagged $ Tuple2 _x3 _x4 :: Bytes2VectorListValFn) - -type Int224ValFn = Tagged "int224Val()" Tuple0 - -int224Val :: TransactionOptions NoPay -> ChainCursor -> Web3 (Either CallError (IntN 224)) -int224Val x1 x2 = map unTuple1 <$> call x1 x2 (tagged Tuple0 :: Int224ValFn) - -type IntListValFn = Tagged "intListVal(uint256)" (Tuple1 (UIntN 256)) - -intListVal - :: TransactionOptions NoPay -> ChainCursor -> UIntN 256 -> Web3 (Either CallError (IntN 256)) -intListVal x1 x2 x3 = intListVal' x1 x2 x3 - where - intListVal' - :: TransactionOptions NoPay -> ChainCursor -> UIntN 256 -> Web3 (Either CallError (IntN 256)) - intListVal' _x1 _x2 _x3 = map unTuple1 <$> call _x1 _x2 (tagged $ Tuple1 _x3 :: IntListValFn) - -type IntValFn = Tagged "intVal()" Tuple0 - -intVal :: TransactionOptions NoPay -> ChainCursor -> Web3 (Either CallError (IntN 256)) -intVal x1 x2 = map unTuple1 <$> call x1 x2 (tagged Tuple0 :: IntValFn) - -type SetValuesFn = Tagged - "setValues(uint256,int256,bool,int224,bool[2],int256[],string,bytes16,bytes2[4][])" - ( Tuple9 (Tagged "_uintVal" (UIntN 256)) (Tagged "_intVal" (IntN 256)) (Tagged "_boolVal" Boolean) - (Tagged "_int224Val" (IntN 224)) - (Tagged "_boolVectorVal" (Vector 2 Boolean)) - (Tagged "_intListVal" (Array (IntN 256))) - (Tagged "_stringVal" String) - (Tagged "_bytes16Val" (BytesN 16)) - (Tagged "_bytes2VectorListVal" (Array (Vector 4 (BytesN 2)))) - ) - -setValues - :: TransactionOptions NoPay - -> { _uintVal :: UIntN 256 - , _intVal :: IntN 256 - , _boolVal :: Boolean - , _int224Val :: IntN 224 - , _boolVectorVal :: Vector 2 Boolean - , _intListVal :: Array (IntN 256) - , _stringVal :: String - , _bytes16Val :: BytesN 16 - , _bytes2VectorListVal :: Array (Vector 4 (BytesN 2)) - } - -> Web3 HexString -setValues x1 x2 = uncurryFields x2 $ setValues' x1 - where - setValues' - :: TransactionOptions NoPay - -> Tagged "_uintVal" (UIntN 256) - -> Tagged "_intVal" (IntN 256) - -> Tagged "_boolVal" Boolean - -> Tagged "_int224Val" (IntN 224) - -> Tagged "_boolVectorVal" (Vector 2 Boolean) - -> Tagged "_intListVal" (Array (IntN 256)) - -> Tagged "_stringVal" String - -> Tagged "_bytes16Val" (BytesN 16) - -> Tagged "_bytes2VectorListVal" (Array (Vector 4 (BytesN 2))) - -> Web3 HexString - setValues' _x1 _x2 _x3 _x4 _x5 _x6 _x7 _x8 _x9 _x10 = sendTx _x1 - (tagged $ Tuple9 _x2 _x3 _x4 _x5 _x6 _x7 _x8 _x9 _x10 :: SetValuesFn) - -type StringValFn = Tagged "stringVal()" Tuple0 - -stringVal :: TransactionOptions NoPay -> ChainCursor -> Web3 (Either CallError String) -stringVal x1 x2 = map unTuple1 <$> call x1 x2 (tagged Tuple0 :: StringValFn) - -type UintValFn = Tagged "uintVal()" Tuple0 - -uintVal :: TransactionOptions NoPay -> ChainCursor -> Web3 (Either CallError (UIntN 256)) -uintVal x1 x2 = map unTuple1 <$> call x1 x2 (tagged Tuple0 :: UintValFn) diff --git a/test/web3/Web3Spec/Live/Contract/MockERC20.purs b/test/web3/Web3Spec/Live/Contract/MockERC20.purs deleted file mode 100644 index 53cdc465..00000000 --- a/test/web3/Web3Spec/Live/Contract/MockERC20.purs +++ /dev/null @@ -1,55 +0,0 @@ -module Web3Spec.Live.Contract.MockERC20 where - -import Prelude - -import Data.Eq.Generic (genericEq) -import Data.Functor.Tagged (Tagged, tagged) -import Data.Generic.Rep (class Generic) -import Data.Lens (set) -import Data.Maybe (Maybe(..), fromJust) -import Data.Newtype (class Newtype) -import Data.Show.Generic (genericShow) -import Network.Ethereum.Web3 (class EventFilter, _address, _topics, sendTx) -import Network.Ethereum.Web3.Contract.Internal (uncurryFields) -import Network.Ethereum.Web3.Solidity (Tuple1, UIntN, Tuple2(..), class IndexedEvent) -import Network.Ethereum.Web3.Types (Address, HexString, NoPay, TransactionOptions, Web3, defaultFilter, mkHexString) -import Partial.Unsafe (unsafePartial) - -newtype Transfer = Transfer { to :: Address, from :: Address, amount :: UIntN 256 } - -derive instance Newtype Transfer _ -derive instance Generic Transfer _ -instance Show Transfer where - show = genericShow - -instance Eq Transfer where - eq = genericEq - -instance EventFilter Transfer where - eventFilter _ addr = defaultFilter # set _address (Just addr) # set _topics - ( Just - [ Just $ unsafePartial $ fromJust $ mkHexString - "ddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef" - , Nothing - , Nothing - ] - ) - -instance - IndexedEvent (Tuple2 (Tagged "to" Address) (Tagged "from" Address)) - (Tuple1 (Tagged "amount" (UIntN 256))) - Transfer where - isAnonymous _ = false - -type TransferFn = Tagged "transfer(address,uint256)" - (Tuple2 (Tagged "to" Address) (Tagged "amount" (UIntN 256))) - -transfer :: TransactionOptions NoPay -> { to :: Address, amount :: UIntN 256 } -> Web3 HexString -transfer x1 x2 = uncurryFields x2 $ transfer' x1 - where - transfer' - :: TransactionOptions NoPay - -> Tagged "to" Address - -> Tagged "amount" (UIntN 256) - -> Web3 HexString - transfer' _x1 _x2 _x3 = sendTx _x1 (tagged $ Tuple2 _x2 _x3 :: TransferFn) diff --git a/test/web3/Web3Spec/Live/Contract/Multifilter.purs b/test/web3/Web3Spec/Live/Contract/Multifilter.purs deleted file mode 100644 index d8b6358f..00000000 --- a/test/web3/Web3Spec/Live/Contract/Multifilter.purs +++ /dev/null @@ -1,74 +0,0 @@ -module Web3Spec.Live.Contract.Multifilter where - -import Prelude - -import Data.Eq.Generic (genericEq) -import Data.Functor.Tagged (Tagged, tagged) -import Data.Generic.Rep (class Generic) -import Data.Lens (set) -import Data.Maybe (Maybe(..), fromJust) -import Data.Newtype (class Newtype) -import Data.Show.Generic (genericShow) -import Network.Ethereum.Web3 (class EventFilter, _address, _topics, sendTx) -import Network.Ethereum.Web3.Contract.Internal (uncurryFields) -import Network.Ethereum.Web3.Solidity (Tuple0, UIntN, Tuple1(..), class IndexedEvent) -import Network.Ethereum.Web3.Types (HexString, NoPay, TransactionOptions, Web3, defaultFilter, mkHexString) -import Partial.Unsafe (unsafePartial) - -newtype E1 = E1 { value1 :: UIntN 256 } - -derive instance Newtype E1 _ -derive instance Generic E1 _ -instance Show E1 where - show = genericShow - -instance Eq E1 where - eq = genericEq - -instance EventFilter E1 where - eventFilter _ addr = defaultFilter # set _address (Just addr) # set _topics - ( Just - [ Just $ unsafePartial $ fromJust $ mkHexString - "47e2689743f14e97f7dcfa5eec10ba1dff02f83b3d1d4b9c07b206cbbda66450" - ] - ) - -instance IndexedEvent Tuple0 (Tuple1 (Tagged "value1" (UIntN 256))) E1 where - isAnonymous _ = false - -newtype E2 = E2 { value2 :: UIntN 256 } - -derive instance Newtype E2 _ -derive instance Generic E2 _ -instance Show E2 where - show = genericShow - -instance Eq E2 where - eq = genericEq - -instance EventFilter E2 where - eventFilter _ addr = defaultFilter # set _address (Just addr) # set _topics - ( Just - [ Just $ unsafePartial $ fromJust $ mkHexString - "a48a6b249a5084126c3da369fbc9b16827ead8cb5cdc094b717d3f1dcd995e29" - ] - ) - -instance IndexedEvent Tuple0 (Tuple1 (Tagged "value2" (UIntN 256))) E2 where - isAnonymous _ = false - -type FireE1Fn = Tagged "fireE1(uint256)" (Tuple1 (Tagged "_value" (UIntN 256))) - -fireE1 :: TransactionOptions NoPay -> { _value :: UIntN 256 } -> Web3 HexString -fireE1 x1 x2 = uncurryFields x2 $ fireE1' x1 - where - fireE1' :: TransactionOptions NoPay -> Tagged "_value" (UIntN 256) -> Web3 HexString - fireE1' _x1 _x2 = sendTx _x1 (tagged $ Tuple1 _x2 :: FireE1Fn) - -type FireE2Fn = Tagged "fireE2(uint256)" (Tuple1 (Tagged "_value" (UIntN 256))) - -fireE2 :: TransactionOptions NoPay -> { _value :: UIntN 256 } -> Web3 HexString -fireE2 x1 x2 = uncurryFields x2 $ fireE2' x1 - where - fireE2' :: TransactionOptions NoPay -> Tagged "_value" (UIntN 256) -> Web3 HexString - fireE2' _x1 _x2 = sendTx _x1 (tagged $ Tuple1 _x2 :: FireE2Fn) diff --git a/test/web3/Web3Spec/Live/Contract/PayableTest.purs b/test/web3/Web3Spec/Live/Contract/PayableTest.purs deleted file mode 100644 index 052efc4e..00000000 --- a/test/web3/Web3Spec/Live/Contract/PayableTest.purs +++ /dev/null @@ -1,42 +0,0 @@ -module Web3Spec.Live.Contract.PayableTest where - -import Prelude - -import Data.Eq.Generic (genericEq) -import Data.Functor.Tagged (Tagged, tagged) -import Data.Generic.Rep (class Generic) -import Data.Lens (set) -import Data.Maybe (Maybe(..), fromJust) -import Data.Newtype (class Newtype) -import Data.Show.Generic (genericShow) -import Network.Ethereum.Web3 (class EventFilter, _address, _topics, sendTx) -import Network.Ethereum.Web3.Solidity (Tuple1, UIntN, Tuple0(..), class IndexedEvent) -import Network.Ethereum.Web3.Types (HexString, TransactionOptions, Web3, defaultFilter, mkHexString) -import Network.Ethereum.Web3.Types.TokenUnit (MinorUnit) -import Partial.Unsafe (unsafePartial) - -newtype Content = Content { _paidContent :: UIntN 256 } - -derive instance Newtype Content _ -derive instance Generic Content _ -instance Show Content where - show = genericShow - -instance Eq Content where - eq = genericEq - -instance EventFilter Content where - eventFilter _ addr = defaultFilter # set _address (Just addr) # set _topics - ( Just - [ Just $ unsafePartial $ fromJust $ mkHexString - "78692973dbc680e9276487808ebf9b485db7b4fbb74c05799e397695b5c7686b" - ] - ) - -instance IndexedEvent Tuple0 (Tuple1 (Tagged "_paidContent" (UIntN 256))) Content where - isAnonymous _ = false - -type SeeContentFn = Tagged "seeContent()" Tuple0 - -seeContent :: TransactionOptions MinorUnit -> Web3 HexString -seeContent x1 = sendTx x1 (tagged Tuple0 :: SeeContentFn) diff --git a/test/web3/Web3Spec/Live/Contract/SimpleErrorTest.purs b/test/web3/Web3Spec/Live/Contract/SimpleErrorTest.purs deleted file mode 100644 index 0d477d97..00000000 --- a/test/web3/Web3Spec/Live/Contract/SimpleErrorTest.purs +++ /dev/null @@ -1,42 +0,0 @@ -module Web3Spec.Live.Contract.SimpleErrorTest where - -import Prelude - -import Data.Either (Either) -import Data.Functor.Tagged (Tagged, tagged) -import Network.Ethereum.Web3 (call) -import Network.Ethereum.Web3.Contract.Internal (uncurryFields) -import Network.Ethereum.Web3.Solidity (UIntN, Tuple1(..), unTuple1) -import Network.Ethereum.Web3.Types (CallError, ChainCursor, NoPay, TransactionOptions, Web3) - -type NamesFn = Tagged "names(uint256)" (Tuple1 (UIntN 256)) - -names :: TransactionOptions NoPay -> ChainCursor -> UIntN 256 -> Web3 (Either CallError String) -names x1 x2 x3 = names' x1 x2 x3 - where - names' :: TransactionOptions NoPay -> ChainCursor -> UIntN 256 -> Web3 (Either CallError String) - names' _x1 _x2 _x3 = map unTuple1 <$> call _x1 _x2 (tagged $ Tuple1 _x3 :: NamesFn) - -type TableFn = Tagged "table(uint256)" (Tuple1 (UIntN 256)) - -table :: TransactionOptions NoPay -> ChainCursor -> UIntN 256 -> Web3 (Either CallError String) -table x1 x2 x3 = table' x1 x2 x3 - where - table' :: TransactionOptions NoPay -> ChainCursor -> UIntN 256 -> Web3 (Either CallError String) - table' _x1 _x2 _x3 = map unTuple1 <$> call _x1 _x2 (tagged $ Tuple1 _x3 :: TableFn) - -type TestBoolFn = Tagged "testBool(bool)" (Tuple1 (Tagged "_arg" Boolean)) - -testBool - :: TransactionOptions NoPay - -> ChainCursor - -> { _arg :: Boolean } - -> Web3 (Either CallError Boolean) -testBool x1 x2 x3 = uncurryFields x3 $ testBool' x1 x2 - where - testBool' - :: TransactionOptions NoPay - -> ChainCursor - -> Tagged "_arg" Boolean - -> Web3 (Either CallError Boolean) - testBool' _x1 _x2 _x3 = map unTuple1 <$> call _x1 _x2 (tagged $ Tuple1 _x3 :: TestBoolFn) diff --git a/test/web3/Web3Spec/Live/Contract/SimpleStorage.purs b/test/web3/Web3Spec/Live/Contract/SimpleStorage.purs deleted file mode 100644 index ca89e106..00000000 --- a/test/web3/Web3Spec/Live/Contract/SimpleStorage.purs +++ /dev/null @@ -1,77 +0,0 @@ -module Web3Spec.Live.Contract.SimpleStorage where - -import Prelude - -import Data.Either (Either) -import Data.Eq.Generic (genericEq) -import Data.Functor.Tagged (Tagged, tagged) -import Data.Generic.Rep (class Generic) -import Data.Lens (set) -import Data.Maybe (Maybe(..), fromJust) -import Data.Newtype (class Newtype) -import Data.Show.Generic (genericShow) -import Network.Ethereum.Web3 (class EventFilter, _address, _topics, call, deployContract, sendTx) -import Network.Ethereum.Web3.Contract.Internal (uncurryFields) -import Network.Ethereum.Web3.Solidity (UIntN, Tuple0(..), Tuple1(..), class IndexedEvent, unTuple1) -import Network.Ethereum.Web3.Types (CallError, ChainCursor, HexString, NoPay, TransactionOptions, Web3, defaultFilter, mkHexString) -import Partial.Unsafe (unsafePartial) - -type ConstructorFn = Tagged Void Tuple0 - -constructor :: TransactionOptions NoPay -> HexString -> Web3 HexString -constructor x1 x2 = deployContract x1 x2 (tagged Tuple0 :: ConstructorFn) - -newtype CountSet = CountSet { _count :: UIntN 256 } - -derive instance Newtype CountSet _ -derive instance Generic CountSet _ -instance Show CountSet where - show = genericShow - -instance Eq CountSet where - eq = genericEq - -instance EventFilter CountSet where - eventFilter _ addr = defaultFilter # set _address (Just addr) # set _topics - ( Just - [ Just $ unsafePartial $ fromJust $ mkHexString - "a32bc18230dd172221ac5c4821a5f1f1a831f27b1396d244cdd891c58f132435" - ] - ) - -instance IndexedEvent Tuple0 (Tuple1 (Tagged "_count" (UIntN 256))) CountSet where - isAnonymous _ = false - -newtype Deployed = Deployed { _blockNumber :: UIntN 256 } - -derive instance Newtype Deployed _ -derive instance Generic Deployed _ -instance Show Deployed where - show = genericShow - -instance Eq Deployed where - eq = genericEq - -instance EventFilter Deployed where - eventFilter _ addr = defaultFilter # set _address (Just addr) # set _topics - ( Just - [ Just $ unsafePartial $ fromJust $ mkHexString - "b94ae47ec9f4248692e2ecf9740b67ab493f3dcc8452bedc7d9cd911c28d1ca5" - ] - ) - -instance IndexedEvent Tuple0 (Tuple1 (Tagged "_blockNumber" (UIntN 256))) Deployed where - isAnonymous _ = false - -type CountFn = Tagged "count()" Tuple0 - -count :: TransactionOptions NoPay -> ChainCursor -> Web3 (Either CallError (UIntN 256)) -count x1 x2 = map unTuple1 <$> call x1 x2 (tagged Tuple0 :: CountFn) - -type SetCountFn = Tagged "setCount(uint256)" (Tuple1 (Tagged "_count" (UIntN 256))) - -setCount :: TransactionOptions NoPay -> { _count :: UIntN 256 } -> Web3 HexString -setCount x1 x2 = uncurryFields x2 $ setCount' x1 - where - setCount' :: TransactionOptions NoPay -> Tagged "_count" (UIntN 256) -> Web3 HexString - setCount' _x1 _x2 = sendTx _x1 (tagged $ Tuple1 _x2 :: SetCountFn) diff --git a/test/web3/Web3Spec/Live/FilterSpec.purs b/test/web3/Web3Spec/Live/FilterSpec.purs deleted file mode 100644 index de00cf7d..00000000 --- a/test/web3/Web3Spec/Live/FilterSpec.purs +++ /dev/null @@ -1,303 +0,0 @@ -module Web3Spec.Live.FilterSpec (spec) where - -import Prelude -import Control.Monad.Reader (ask) -import Control.Monad.Trans.Class (lift) -import Data.Array ((..), snoc, length, head, sortWith) -import Data.Either (Either) -import Data.Maybe (Maybe(..)) -import Data.Newtype (wrap, unwrap, un) -import Data.Ord.Down (Down(..)) -import Data.Traversable (traverse_) -import Data.Lens ((?~), (.~), (^.)) -import Effect.Aff (Aff, Fiber, error) -import Effect.Class (liftEffect) -import Effect.Aff.Class (class MonadAff, liftAff) -import Effect.Aff.AVar as AVar -import Effect.AVar as EAVar -import Network.Ethereum.Web3 (BlockNumber(..), throwWeb3, Filter, Web3Error, Change(..), _fromBlock, _toBlock, eventFilter, EventAction(..), forkWeb3, ChainCursor(..), Provider, UIntN, _from, _to, embed, Address, event') -import Network.Ethereum.Web3.Api as Api -import Network.Ethereum.Web3.Solidity.Sizes (s256) -import Partial.Unsafe (unsafeCrashWith) -import Test.Spec (SpecT, before, describe, it, parallel) -import Test.Spec.Assertions (shouldEqual) -import Type.Proxy (Proxy(..)) -import Web3Spec.Live.Contract.SimpleStorage as SimpleStorage -import Web3Spec.Live.Code.SimpleStorage as SimpleStorageCode -import Web3Spec.Live.Utils (assertWeb3, go, Logger, defaultTestTxOptions, ContractConfig, deployContract, mkUIntN, pollTransactionReceipt, joinWeb3Fork, hangOutTillBlock) - -spec :: Provider -> SpecT Aff Unit Aff Unit -spec p = - let - env = - { logger: \s -> ask >>= \logger -> liftAff $ logger s - } - in - go $ spec' p env - -type FilterEnv m = - { logger :: String -> m Unit - } - -{- -NOTE: none of the Futures use Pending, the behavior is currently ill defined - -Case [Past,Past] : The filter is starting and ending in the past. -Case [Past, ∞] : The filter starts in the past but continues indefinitely into the future. -Case [Future, ∞] : The fitler starts in the future and continues indefinitely into the future. -Case [Future, Future] : The fitler starts in the future and ends at a later time in the future. --} -spec' - :: forall m - . MonadAff m - => Provider - -> FilterEnv m - -> SpecT m Unit Aff Unit -spec' provider { logger } = do - uIntV <- liftEffect $ EAVar.new 1 - let - gen = mkUIntsGen uIntV - describe "Filters" - $ parallel do - before (deployUniqueSimpleStorage provider logger gen) - $ it "Case [Past, Past]" \simpleStorageCfg -> do - let - { simpleStorageAddress, setter, uIntsGen } = simpleStorageCfg - - filter = eventFilter (Proxy :: Proxy SimpleStorage.CountSet) simpleStorageAddress - values <- uIntsGen 3 - logger $ "Searching for values " <> show values - fiber <- monitorUntil provider logger filter (_ == aMax values) defaultFilterOpts - start <- assertWeb3 provider Api.eth_blockNumber - traverse_ setter values - { endingBlockV } <- joinWeb3Fork fiber - end <- liftAff $ AVar.take endingBlockV - let - pastFilter = - eventFilter (Proxy :: Proxy SimpleStorage.CountSet) simpleStorageAddress - # _fromBlock - .~ BN start - # _toBlock - .~ BN end - fiber' <- monitorUntil provider logger pastFilter (const false) defaultFilterOpts - { foundValuesV } <- joinWeb3Fork fiber' - foundValues <- liftAff $ AVar.take foundValuesV - liftAff $ foundValues `shouldEqual` values - before (deployUniqueSimpleStorage provider logger gen) - $ do - it "Case [Past, ∞] No Trail" \simpleStorageCfg -> do - fromPastToFutureTrailingBy simpleStorageCfg provider logger defaultFilterOpts - it "Case [Past, ∞] With Trail" \simpleStorageCfg -> do - fromPastToFutureTrailingBy simpleStorageCfg provider logger { trailBy: 3, windowSize: 2 } - before (deployUniqueSimpleStorage provider logger gen) - $ it "Case [Future, ∞]" \simpleStorageCfg -> do - let - { simpleStorageAddress, setter, uIntsGen } = simpleStorageCfg - values <- uIntsGen 3 - logger $ "Searching for values " <> show values - now <- assertWeb3 provider Api.eth_blockNumber - let - later = wrap $ unwrap now + embed 3 - - filter = - eventFilter (Proxy :: Proxy SimpleStorage.CountSet) simpleStorageAddress - # _fromBlock - .~ BN later - # _toBlock - .~ Latest - fiber <- monitorUntil provider logger filter (_ == aMax values) defaultFilterOpts - hangOutTillBlock provider logger later - traverse_ setter values - { foundValuesV } <- joinWeb3Fork fiber - foundValues <- liftAff $ AVar.take foundValuesV - liftAff $ foundValues `shouldEqual` values - before (deployUniqueSimpleStorage provider logger gen) - $ it "Case [Future, Future]" \simpleStorageCfg -> do - let - { simpleStorageAddress, setter, uIntsGen } = simpleStorageCfg - values <- uIntsGen 3 - logger $ "Searching for values " <> show values - let - nValues = length values - now <- assertWeb3 provider Api.eth_blockNumber - let - later = wrap $ unwrap now + embed 3 - - -- NOTE: This isn't that clean, but 2 blocks per set should be enough time - latest = wrap $ unwrap later + embed (2 * nValues) - - filter = - eventFilter (Proxy :: Proxy SimpleStorage.CountSet) simpleStorageAddress - # _fromBlock - .~ BN later - # _toBlock - .~ BN latest - fiber <- monitorUntil provider logger filter (_ == aMax values) defaultFilterOpts - hangOutTillBlock provider logger later - traverse_ setter values - { foundValuesV } <- joinWeb3Fork fiber - foundValues <- liftAff $ AVar.take foundValuesV - liftAff $ foundValues `shouldEqual` values - --------------------------------------------------------------------------------- --- Utils --------------------------------------------------------------------------------- -type FilterOpts = - { trailBy :: Int - , windowSize :: Int - } - -defaultFilterOpts :: FilterOpts -defaultFilterOpts = { trailBy: 0, windowSize: 0 } - -fromPastToFutureTrailingBy - :: forall m - . MonadAff m - => SimpleStorageCfg m - -> Provider - -> Logger m - -> FilterOpts - -> m Unit -fromPastToFutureTrailingBy simpleStorageCfg provider logger opts = do - let - { simpleStorageAddress, setter, uIntsGen } = simpleStorageCfg - - filter1 = eventFilter (Proxy :: Proxy SimpleStorage.CountSet) simpleStorageAddress - firstValues <- uIntsGen 7 - secondValues <- uIntsGen 7 - let - allValues = firstValues <> secondValues - logger $ "Searching for values " <> show allValues - fiber1 <- monitorUntil provider logger filter1 (_ == aMax firstValues) defaultFilterOpts - start <- assertWeb3 provider Api.eth_blockNumber - traverse_ setter firstValues - _ <- joinWeb3Fork fiber1 - let - filter2 = - eventFilter (Proxy :: Proxy SimpleStorage.CountSet) simpleStorageAddress - # _fromBlock - .~ BN start - # _toBlock - .~ Latest - fiber2 <- monitorUntil provider logger filter2 (_ == aMax secondValues) opts - traverse_ setter secondValues - { foundValuesV, reachedTargetTrailByV } <- joinWeb3Fork fiber2 - foundValues <- liftAff $ AVar.take foundValuesV - liftAff $ foundValues `shouldEqual` allValues - when (opts.trailBy > 0) do - reachedTargetTrailBy <- liftAff $ AVar.take reachedTargetTrailByV - logger $ "Reached 'chainHead - trailBy' : " <> show reachedTargetTrailBy - liftAff $ reachedTargetTrailBy `shouldEqual` true - -monitorUntil - :: forall m - . MonadAff m - => Provider - -> Logger m - -> Filter SimpleStorage.CountSet - -> (UIntN 256 -> Boolean) - -> FilterOpts - -> m - ( Fiber - ( Either Web3Error - { endingBlockV :: AVar.AVar BlockNumber - , foundValuesV :: AVar.AVar (Array (UIntN 256)) - , reachedTargetTrailByV :: AVar.AVar Boolean - } - ) - ) -monitorUntil provider logger filter p opts = do - endingBlockV <- liftAff AVar.empty - foundValuesV <- liftAff $ AVar.new [] - reachedTargetTrailByV <- liftAff $ AVar.new false - logger $ "Creating filter with fromBlock=" - <> show (filter ^. _fromBlock) - <> " toBlock=" - <> show (filter ^. _toBlock) - let - handler (SimpleStorage.CountSet { _count }) = do - Change c <- ask - chainHead <- lift Api.eth_blockNumber - when (un BlockNumber chainHead - un BlockNumber c.blockNumber < embed opts.trailBy) - $ lift - $ throwWeb3 - $ error "Exceded max trailBy" - when (un BlockNumber chainHead - un BlockNumber c.blockNumber == embed opts.trailBy) do - _ <- liftAff $ AVar.take reachedTargetTrailByV - liftAff $ AVar.put true reachedTargetTrailByV - foundSoFar <- liftAff $ AVar.take foundValuesV - liftAff $ AVar.put (foundSoFar `snoc` _count) foundValuesV - let - shouldTerminate = p _count - if shouldTerminate then do - liftAff $ AVar.put c.blockNumber endingBlockV - pure TerminateEvent - else - pure ContinueEvent - liftAff $ forkWeb3 provider - $ do - _ <- event' { ev: filter } { ev: handler } opts - pure { endingBlockV, foundValuesV, reachedTargetTrailByV } - -type SimpleStorageCfg m = - { simpleStorageAddress :: Address - , setter :: UIntN 256 -> m Unit - , uIntsGen :: Int -> m (Array (UIntN 256)) - } - -deployUniqueSimpleStorage - :: forall m - . MonadAff m - => Provider - -> Logger m - -> (Int -> m (Array (UIntN 256))) - -> m (SimpleStorageCfg m) -deployUniqueSimpleStorage provider logger uIntsGen = do - contractConfig <- - deployContract provider logger "SimpleStorage" - $ \txOpts -> - SimpleStorage.constructor txOpts SimpleStorageCode.deployBytecode - pure - { simpleStorageAddress: contractConfig.contractAddress - , setter: mkSetter contractConfig provider logger - , uIntsGen - } - -mkSetter - :: forall m - . MonadAff m - => ContractConfig - -> Provider - -> Logger m - -> UIntN 256 - -> m Unit -mkSetter { contractAddress, userAddress } provider logger _count = do - let - txOptions = - defaultTestTxOptions # _from ?~ userAddress - # _to - ?~ contractAddress - logger $ "Setting count to " <> show _count - txHash <- assertWeb3 provider $ SimpleStorage.setCount txOptions { _count } - pollTransactionReceipt provider txHash mempty - -mkUIntsGen - :: forall m - . MonadAff m - => AVar.AVar Int - -> Int - -> m (Array (UIntN 256)) -mkUIntsGen uintV n = - liftAff do - firstAvailable <- AVar.take uintV - let - nextVal = firstAvailable + n - - res = firstAvailable .. (nextVal - 1) - AVar.put nextVal uintV - pure $ map (mkUIntN s256) res - -aMax :: forall a. Ord a => Array a -> a -aMax as = case head $ sortWith Down as of - Nothing -> unsafeCrashWith "Can't take the max of an empty array" - Just a -> a diff --git a/test/web3/Web3Spec/Live/MockERC20Spec.purs b/test/web3/Web3Spec/Live/MockERC20Spec.purs deleted file mode 100644 index b296213b..00000000 --- a/test/web3/Web3Spec/Live/MockERC20Spec.purs +++ /dev/null @@ -1,46 +0,0 @@ -module Web3Spec.Live.MockERC20Spec where - -import Prelude -import Data.Lens ((?~)) -import Data.Tuple (Tuple(..)) -import Effect.Aff (Aff) -import Effect.Class.Console as C -import Network.Ethereum.Web3 (Provider, _from, _to, _value, mkValue, Value, Wei, _data) -import Network.Ethereum.Web3.Api as Api -import Network.Ethereum.Web3.Solidity.Sizes (s256) -import Test.Spec (SpecT, beforeAll, describe, it) -import Test.Spec.Assertions (shouldEqual) -import Type.Proxy (Proxy(..)) -import Web3Spec.Live.Contract.MockERC20 as MockERC20 -import Web3Spec.Live.Code.MockERC20 as MockERC20Code -import Web3Spec.Live.Utils (assertWeb3, defaultTestTxOptions, deployContract, mkUIntN, takeEvent, nullAddress) - -spec :: Provider -> SpecT Aff Unit Aff Unit -spec provider = - describe "MockERC20" - $ beforeAll - ( deployContract provider C.log "MockERC20" - $ \txOpts -> - Api.eth_sendTransaction $ txOpts # _data ?~ MockERC20Code.deployBytecode - # _value - ?~ (mkValue zero :: Value Wei) - ) - $ it "can make a transfer" - $ \cfg -> do - let - { contractAddress: mockERC20Address, userAddress } = cfg - - amount = mkUIntN s256 1 - - recipient = nullAddress - - txOptions = - defaultTestTxOptions # _from ?~ userAddress - # _to - ?~ mockERC20Address - - transferAction = MockERC20.transfer txOptions { to: recipient, amount: amount } - Tuple _ (MockERC20.Transfer tfr) <- - assertWeb3 provider - $ takeEvent (Proxy :: Proxy MockERC20.Transfer) mockERC20Address transferAction - tfr.amount `shouldEqual` amount diff --git a/test/web3/Web3Spec/Live/MultifilterSpec.purs b/test/web3/Web3Spec/Live/MultifilterSpec.purs deleted file mode 100644 index 1b8adc30..00000000 --- a/test/web3/Web3Spec/Live/MultifilterSpec.purs +++ /dev/null @@ -1,126 +0,0 @@ -module Web3Spec.Live.MultifilterSpec (spec) where - -import Prelude -import Control.Monad.Reader (ask) -import Data.Array (snoc, (..), length, sort) -import Data.Bifunctor (rmap) -import Data.Lens ((?~)) -import Data.Tuple (Tuple(..)) -import Control.Parallel (parSequence_, parTraverse_) -import Effect.Aff (Aff) -import Effect.Aff.Class (liftAff) -import Effect.Aff.AVar as AVar -import Effect.Class.Console as C -import Network.Ethereum.Web3.Api as Api -import Network.Ethereum.Web3 (Provider, BlockNumber, EventHandler, Web3, event, event', BigNumber, forkWeb3, eventFilter, EventAction(..), Change(..), _data, _from, _to, _value, mkValue, Value, Wei) -import Network.Ethereum.Web3.Solidity.Sizes (s256) -import Test.Spec (SpecT, describe, it, beforeAll) -import Test.Spec.Assertions (shouldEqual, shouldNotEqual) -import Type.Proxy (Proxy(..)) -import Web3Spec.Live.Utils (deployContract, defaultTestTxOptions, mkUIntN, assertWeb3, joinWeb3Fork, awaitNextBlock) -import Web3Spec.Live.Code.Multifilter as MultifilterCode -import Web3Spec.Live.Contract.Multifilter as Multifilter - -spec :: Provider -> SpecT Aff Unit Aff Unit -spec provider = - describe "Multifilter" - $ beforeAll - ( deployContract provider C.log "Multifilter" - $ \txOpts -> - Api.eth_sendTransaction $ txOpts # _data ?~ MultifilterCode.deployBytecode - # _value - ?~ (mkValue zero :: Value Wei) - ) - $ it "can receive multiple events in the correct order" \contractCfg -> do - let - { contractAddress: multifilterAddress, userAddress } = contractCfg - - txOpts = - defaultTestTxOptions - # _from - ?~ userAddress - # _to - ?~ multifilterAddress - - vals1 = 1 .. 5 - - vals2 = 6 .. 10 - - nVals = length vals1 + length vals2 - - fireE1 n = void $ assertWeb3 provider $ Multifilter.fireE1 txOpts { _value: mkUIntN s256 n } - - fireE2 n = void $ assertWeb3 provider $ Multifilter.fireE2 txOpts { _value: mkUIntN s256 n } - - filter1 = eventFilter (Proxy :: Proxy Multifilter.E1) multifilterAddress - - filter2 = eventFilter (Proxy :: Proxy Multifilter.E2) multifilterAddress - raceV <- AVar.new [] - count1V <- AVar.new 0 - f1 <- - forkWeb3 provider - $ - let - h1 = mkHandler (Proxy :: Proxy Multifilter.E1) provider raceV count1V (_ == length vals1) true - in - void $ event filter1 h1 - count2V <- AVar.new 0 - f2 <- - forkWeb3 provider - $ - let - h2 = mkHandler (Proxy :: Proxy Multifilter.E2) provider raceV count2V (_ == length vals2) false - in - void $ event filter2 h2 - syncV <- AVar.new [] - sharedCountV <- AVar.new 0 - let - multiFilter = { e1: filter1, e2: filter2 } - - h1 = mkHandler (Proxy :: Proxy Multifilter.E1) provider syncV sharedCountV (_ == nVals) true - - h2 = mkHandler (Proxy :: Proxy Multifilter.E2) provider syncV sharedCountV (_ == nVals) false - - multiHandler = { e1: h1, e2: h2 } - f3 <- do - f <- forkWeb3 provider $ event' multiFilter multiHandler { trailBy: 0, windowSize: 0 } - pure $ (rmap (const unit) <$> f) - parSequence_ - $ - [ parTraverse_ fireE1 vals1 - , parTraverse_ fireE2 vals2 - ] - parTraverse_ joinWeb3Fork [ f1, f2, f3 ] - race <- AVar.take raceV - sync <- AVar.take syncV - race `shouldNotEqual` sync - sort race `shouldEqual` sync - sort sync `shouldEqual` sync - -mkHandler - :: forall e - . Proxy e - -> Provider - -> AVar.AVar (Array (Tuple BlockNumber BigNumber)) - -> AVar.AVar Int - -> (Int -> Boolean) - -> Boolean - -> EventHandler Web3 e -mkHandler _ provider indexV countV p shouldDelay = \_ -> do - Change c <- ask - iAcc <- liftAff $ AVar.take indexV - let - index = Tuple c.blockNumber c.logIndex - - indices = iAcc `snoc` index - liftAff $ AVar.put indices indexV - count <- liftAff $ AVar.take countV - let - count' = count + 1 - liftAff $ AVar.put count' countV - if p count' then - pure TerminateEvent - else do - when shouldDelay - $ awaitNextBlock provider C.log - pure ContinueEvent diff --git a/test/web3/Web3Spec/Live/PayableTestSpec.purs b/test/web3/Web3Spec/Live/PayableTestSpec.purs deleted file mode 100644 index 7b136d13..00000000 --- a/test/web3/Web3Spec/Live/PayableTestSpec.purs +++ /dev/null @@ -1,61 +0,0 @@ -module Web3Spec.Live.PayableTestSpec (spec) where - -import Prelude -import Data.Lens ((?~)) -import Data.Tuple (Tuple(..)) -import Effect.Aff (Aff) -import Effect.Class.Console as C -import Network.Ethereum.Web3 (Provider, _from, _to, _value, mkValue, Value, Wei, Ether, Shannon, _data, unUIntN, convert) -import Network.Ethereum.Web3.Api as Api -import Test.Spec (SpecT, beforeAll, describe, it) -import Test.Spec.Assertions (shouldEqual) -import Type.Proxy (Proxy(..)) -import Web3Spec.Live.Contract.PayableTest as PayableTest -import Web3Spec.Live.Code.PayableTest as PayableTestCode -import Web3Spec.Live.Utils (assertWeb3, defaultTestTxOptions, deployContract, takeEvent) - -spec :: Provider -> SpecT Aff Unit Aff Unit -spec provider = - describe "PayableTest" - $ beforeAll - ( deployContract provider C.log "PayableTest" - $ \txOpts -> - Api.eth_sendTransaction $ txOpts # _data ?~ PayableTestCode.deployBytecode - # _value - ?~ (mkValue zero :: Value Wei) - ) - $ describe "PayableTest" do - it "can send the right amount of Ether" - $ \cfg -> do - let - { contractAddress: payableTestAddress, userAddress } = cfg - - txOptions = - defaultTestTxOptions # _to ?~ payableTestAddress - # _value - ?~ convert (mkValue one :: Value Ether) - # _from - ?~ userAddress - - etherAction = PayableTest.seeContent txOptions - Tuple _ (PayableTest.Content c) <- - assertWeb3 provider - $ takeEvent (Proxy :: Proxy PayableTest.Content) payableTestAddress etherAction - unUIntN c._paidContent `shouldEqual` one - it "can send the right amount of Shannon" - $ \cfg -> do - let - { contractAddress: payableTestAddress, userAddress } = cfg - - txOptions = - defaultTestTxOptions # _to ?~ payableTestAddress - # _value - ?~ convert (mkValue one :: Value Shannon) - # _from - ?~ userAddress - - etherAction = PayableTest.seeContent txOptions - Tuple _ (PayableTest.Content c) <- - assertWeb3 provider - $ takeEvent (Proxy :: Proxy PayableTest.Content) payableTestAddress etherAction - unUIntN c._paidContent `shouldEqual` zero diff --git a/test/web3/Web3Spec/Live/SimpleErrorTestSpec.purs b/test/web3/Web3Spec/Live/SimpleErrorTestSpec.purs deleted file mode 100644 index ef57ddb9..00000000 --- a/test/web3/Web3Spec/Live/SimpleErrorTestSpec.purs +++ /dev/null @@ -1,44 +0,0 @@ -module Web3Spec.Live.SimpleErrorTestSpec (spec) where - -import Prelude -import Data.Either (Either(..), isLeft) -import Data.Lens ((?~)) -import Effect.Aff (Aff) -import Effect.Class.Console as C -import Network.Ethereum.Web3 (Provider, ChainCursor(..), _from, _to, _value, mkValue, Value, Wei, _data) -import Network.Ethereum.Web3.Solidity.Sizes (s256) -import Network.Ethereum.Web3.Api as Api -import Test.Spec (SpecT, beforeAll, describe, it) -import Test.Spec.Assertions (shouldEqual, shouldSatisfy) -import Web3Spec.Live.Contract.SimpleErrorTest as SimpleErrorTest -import Web3Spec.Live.Code.SimpleErrorTest as SimpleErrorTestCode -import Web3Spec.Live.Utils (assertWeb3, defaultTestTxOptions, deployContract, mkUIntN) - -spec :: Provider -> SpecT Aff Unit Aff Unit -spec provider = - describe "SimpleError" - $ beforeAll - ( deployContract provider C.log "SimpleErrorTest" - $ \txOpts -> - Api.eth_sendTransaction $ txOpts # _data ?~ SimpleErrorTestCode.deployBytecode - # _value - ?~ (mkValue zero :: Value Wei) - ) - $ describe "SimpleError" do - it "can raise a left for unset values" - $ \cfg -> do - let - { contractAddress: simpleErrorTestAddress, userAddress } = cfg - - txOptions = - defaultTestTxOptions # _to ?~ simpleErrorTestAddress - # _from - ?~ userAddress - - n = mkUIntN s256 1 - resp1 <- assertWeb3 provider $ SimpleErrorTest.names txOptions Latest n - resp1 `shouldSatisfy` isLeft - resp2 <- assertWeb3 provider $ SimpleErrorTest.testBool txOptions Latest { _arg: true } - resp2 `shouldEqual` Right false - resp3 <- assertWeb3 provider $ SimpleErrorTest.testBool txOptions Latest { _arg: false } - resp3 `shouldEqual` Right true diff --git a/test/web3/Web3Spec/Live/SimpleStorageSpec.purs b/test/web3/Web3Spec/Live/SimpleStorageSpec.purs deleted file mode 100644 index d68edd25..00000000 --- a/test/web3/Web3Spec/Live/SimpleStorageSpec.purs +++ /dev/null @@ -1,45 +0,0 @@ -module Web3Spec.Live.SimpleStorageSpec (spec) where - -import Prelude -import Data.Either (isRight) -import Data.Lens ((?~)) -import Data.Tuple (Tuple(..)) -import Effect.Aff (Aff) -import Effect.Class.Console as C -import Network.Ethereum.Web3 (ChainCursor(..), Provider, _from, _to, runWeb3) -import Network.Ethereum.Web3.Api as Api -import Network.Ethereum.Web3.Solidity.Sizes (s256) -import Test.Spec (SpecT, beforeAll, describe, it) -import Test.Spec.Assertions (shouldEqual, shouldSatisfy) -import Type.Proxy (Proxy(..)) -import Web3Spec.Live.Contract.SimpleStorage as SimpleStorage -import Web3Spec.Live.Code.SimpleStorage as SimpleStorageCode -import Web3Spec.Live.Utils (assertWeb3, defaultTestTxOptions, deployContract, mkUIntN, takeEvent) - -spec :: Provider -> SpecT Aff Unit Aff Unit -spec provider = - describe "Simple Storage" - $ beforeAll - ( deployContract provider C.log "SimpleStorage" - $ \txOpts -> - SimpleStorage.constructor txOpts SimpleStorageCode.deployBytecode - ) - $ it "Can get and set a simple UInt with events" - $ \simpleStorageCfg -> do - let - { contractAddress: simpleStorageAddress, userAddress } = simpleStorageCfg - - newCount = mkUIntN s256 1 - - txOpts = - defaultTestTxOptions # _from ?~ userAddress - # _to - ?~ simpleStorageAddress - - setCountTx = SimpleStorage.setCount txOpts { _count: newCount } - Tuple _ (SimpleStorage.CountSet { _count }) <- - assertWeb3 provider - $ takeEvent (Proxy :: Proxy SimpleStorage.CountSet) simpleStorageAddress setCountTx - _count `shouldEqual` newCount - eRes' <- runWeb3 provider $ Api.eth_getStorageAt simpleStorageAddress zero Latest - eRes' `shouldSatisfy` isRight