Skip to content

Commit

Permalink
tests passing
Browse files Browse the repository at this point in the history
  • Loading branch information
martyall committed Mar 20, 2018
1 parent 5b428fc commit 12b1f29
Show file tree
Hide file tree
Showing 5 changed files with 48 additions and 18 deletions.
2 changes: 1 addition & 1 deletion build/contracts/SimpleStorage.json
Original file line number Diff line number Diff line change
@@ -1 +1 @@
{"contractName":"SimpleStorage","abi":[{"constant":true,"inputs":[],"name":"count","outputs":[{"name":"","type":"uint256"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":false,"inputs":[{"name":"_count","type":"uint256"}],"name":"setCount","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"},{"inputs":[{"name":"_count","type":"uint256"}],"payable":false,"stateMutability":"nonpayable","type":"constructor"},{"anonymous":false,"inputs":[{"indexed":false,"name":"_count","type":"uint256"}],"name":"CountSet","type":"event"}],"bytecode":"0x6060604052341561000f57600080fd5b604051602080610149833981016040528080519060200190919050508060008190555050610107806100426000396000f3006060604052600436106049576000357c0100000000000000000000000000000000000000000000000000000000900463ffffffff16806306661abd14604e578063d14e62b8146074575b600080fd5b3415605857600080fd5b605e6094565b6040518082815260200191505060405180910390f35b3415607e57600080fd5b60926004808035906020019091905050609a565b005b60005481565b806000819055507fa32bc18230dd172221ac5c4821a5f1f1a831f27b1396d244cdd891c58f132435816040518082815260200191505060405180910390a1505600a165627a7a72305820b648c68bc68fb31b11c40305c410b178eb7295c16f641511e8a5f6b0a9d65f650029","deployedBytecode":"0x6060604052600436106049576000357c0100000000000000000000000000000000000000000000000000000000900463ffffffff16806306661abd14604e578063d14e62b8146074575b600080fd5b3415605857600080fd5b605e6094565b6040518082815260200191505060405180910390f35b3415607e57600080fd5b60926004808035906020019091905050609a565b005b60005481565b806000819055507fa32bc18230dd172221ac5c4821a5f1f1a831f27b1396d244cdd891c58f132435816040518082815260200191505060405180910390a1505600a165627a7a72305820b648c68bc68fb31b11c40305c410b178eb7295c16f641511e8a5f6b0a9d65f650029","sourceMap":"26:265:0:-;;;113:74;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;174:6;166:5;:14;;;;113:74;26:265;;;;;;","deployedSourceMap":"26:265:0:-;;;;;;;;;;;;;;;;;;;;;;;;;;;;;55:17;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;194:95;;;;;;;;;;;;;;;;;;;;;;;;;;55:17;;;;:::o;194:95::-;250:6;242:5;:14;;;;266:16;275:6;266:16;;;;;;;;;;;;;;;;;;194:95;:::o","source":"pragma solidity ^0.4.15;\n\ncontract SimpleStorage {\n uint public count;\n\n event CountSet(uint _count);\n\n function SimpleStorage(uint _count) public {\n count = _count;\n } \n\n function setCount(uint _count) public {\n count = _count;\n CountSet(_count);\n }\n}\n","sourcePath":"/Users/martyall/code/foam/foam.contracts.deux/contracts/SimpleStorage.sol","ast":{"attributes":{"absolutePath":"/Users/martyall/code/foam/foam.contracts.deux/contracts/SimpleStorage.sol","exportedSymbols":{"SimpleStorage":[32]}},"children":[{"attributes":{"literals":["solidity","^","0.4",".15"]},"id":1,"name":"PragmaDirective","src":"0:24:0"},{"attributes":{"baseContracts":[null],"contractDependencies":[null],"contractKind":"contract","documentation":null,"fullyImplemented":true,"linearizedBaseContracts":[32],"name":"SimpleStorage","scope":33},"children":[{"attributes":{"constant":false,"name":"count","scope":32,"stateVariable":true,"storageLocation":"default","type":"uint256","value":null,"visibility":"public"},"children":[{"attributes":{"name":"uint","type":"uint256"},"id":2,"name":"ElementaryTypeName","src":"55:4:0"}],"id":3,"name":"VariableDeclaration","src":"55:17:0"},{"attributes":{"anonymous":false,"name":"CountSet"},"children":[{"children":[{"attributes":{"constant":false,"indexed":false,"name":"_count","scope":7,"stateVariable":false,"storageLocation":"default","type":"uint256","value":null,"visibility":"internal"},"children":[{"attributes":{"name":"uint","type":"uint256"},"id":4,"name":"ElementaryTypeName","src":"94:4:0"}],"id":5,"name":"VariableDeclaration","src":"94:11:0"}],"id":6,"name":"ParameterList","src":"93:13:0"}],"id":7,"name":"EventDefinition","src":"79:28:0"},{"attributes":{"constant":false,"implemented":true,"isConstructor":true,"modifiers":[null],"name":"SimpleStorage","payable":false,"scope":32,"stateMutability":"nonpayable","superFunction":null,"visibility":"public"},"children":[{"children":[{"attributes":{"constant":false,"name":"_count","scope":17,"stateVariable":false,"storageLocation":"default","type":"uint256","value":null,"visibility":"internal"},"children":[{"attributes":{"name":"uint","type":"uint256"},"id":8,"name":"ElementaryTypeName","src":"136:4:0"}],"id":9,"name":"VariableDeclaration","src":"136:11:0"}],"id":10,"name":"ParameterList","src":"135:13:0"},{"attributes":{"parameters":[null]},"children":[],"id":11,"name":"ParameterList","src":"156:0:0"},{"children":[{"children":[{"attributes":{"argumentTypes":null,"isConstant":false,"isLValue":false,"isPure":false,"lValueRequested":false,"operator":"=","type":"uint256"},"children":[{"attributes":{"argumentTypes":null,"overloadedDeclarations":[null],"referencedDeclaration":3,"type":"uint256","value":"count"},"id":12,"name":"Identifier","src":"166:5:0"},{"attributes":{"argumentTypes":null,"overloadedDeclarations":[null],"referencedDeclaration":9,"type":"uint256","value":"_count"},"id":13,"name":"Identifier","src":"174:6:0"}],"id":14,"name":"Assignment","src":"166:14:0"}],"id":15,"name":"ExpressionStatement","src":"166:14:0"}],"id":16,"name":"Block","src":"156:31:0"}],"id":17,"name":"FunctionDefinition","src":"113:74:0"},{"attributes":{"constant":false,"implemented":true,"isConstructor":false,"modifiers":[null],"name":"setCount","payable":false,"scope":32,"stateMutability":"nonpayable","superFunction":null,"visibility":"public"},"children":[{"children":[{"attributes":{"constant":false,"name":"_count","scope":31,"stateVariable":false,"storageLocation":"default","type":"uint256","value":null,"visibility":"internal"},"children":[{"attributes":{"name":"uint","type":"uint256"},"id":18,"name":"ElementaryTypeName","src":"212:4:0"}],"id":19,"name":"VariableDeclaration","src":"212:11:0"}],"id":20,"name":"ParameterList","src":"211:13:0"},{"attributes":{"parameters":[null]},"children":[],"id":21,"name":"ParameterList","src":"232:0:0"},{"children":[{"children":[{"attributes":{"argumentTypes":null,"isConstant":false,"isLValue":false,"isPure":false,"lValueRequested":false,"operator":"=","type":"uint256"},"children":[{"attributes":{"argumentTypes":null,"overloadedDeclarations":[null],"referencedDeclaration":3,"type":"uint256","value":"count"},"id":22,"name":"Identifier","src":"242:5:0"},{"attributes":{"argumentTypes":null,"overloadedDeclarations":[null],"referencedDeclaration":19,"type":"uint256","value":"_count"},"id":23,"name":"Identifier","src":"250:6:0"}],"id":24,"name":"Assignment","src":"242:14:0"}],"id":25,"name":"ExpressionStatement","src":"242:14:0"},{"children":[{"attributes":{"argumentTypes":null,"isConstant":false,"isLValue":false,"isPure":false,"isStructConstructorCall":false,"lValueRequested":false,"names":[null],"type":"tuple()","type_conversion":false},"children":[{"attributes":{"argumentTypes":[{"typeIdentifier":"t_uint256","typeString":"uint256"}],"overloadedDeclarations":[null],"referencedDeclaration":7,"type":"function (uint256)","value":"CountSet"},"id":26,"name":"Identifier","src":"266:8:0"},{"attributes":{"argumentTypes":null,"overloadedDeclarations":[null],"referencedDeclaration":19,"type":"uint256","value":"_count"},"id":27,"name":"Identifier","src":"275:6:0"}],"id":28,"name":"FunctionCall","src":"266:16:0"}],"id":29,"name":"ExpressionStatement","src":"266:16:0"}],"id":30,"name":"Block","src":"232:57:0"}],"id":31,"name":"FunctionDefinition","src":"194:95:0"}],"id":32,"name":"ContractDefinition","src":"26:265:0"}],"id":33,"name":"SourceUnit","src":"0:292:0"},"compiler":{"name":"solc","version":"0.4.18+commit.9cf6e910.Emscripten.clang"},"networks":{"420123":{"address":"0x8e4319afafa9647ebe68a744f853352aa8602573"}},"schemaVersion":"1.0.1","updatedAt":"2018-03-20T17:42:03.220Z"}
{"contractName":"SimpleStorage","abi":[{"constant":true,"inputs":[],"name":"count","outputs":[{"name":"","type":"uint256"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":false,"inputs":[{"name":"_count","type":"uint256"}],"name":"setCount","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"},{"inputs":[{"name":"_count","type":"uint256"}],"payable":false,"stateMutability":"nonpayable","type":"constructor"},{"anonymous":false,"inputs":[{"indexed":false,"name":"_count","type":"uint256"}],"name":"CountSet","type":"event"}],"bytecode":"0x6060604052341561000f57600080fd5b604051602080610149833981016040528080519060200190919050508060008190555050610107806100426000396000f3006060604052600436106049576000357c0100000000000000000000000000000000000000000000000000000000900463ffffffff16806306661abd14604e578063d14e62b8146074575b600080fd5b3415605857600080fd5b605e6094565b6040518082815260200191505060405180910390f35b3415607e57600080fd5b60926004808035906020019091905050609a565b005b60005481565b806000819055507fa32bc18230dd172221ac5c4821a5f1f1a831f27b1396d244cdd891c58f132435816040518082815260200191505060405180910390a1505600a165627a7a72305820b648c68bc68fb31b11c40305c410b178eb7295c16f641511e8a5f6b0a9d65f650029","deployedBytecode":"0x6060604052600436106049576000357c0100000000000000000000000000000000000000000000000000000000900463ffffffff16806306661abd14604e578063d14e62b8146074575b600080fd5b3415605857600080fd5b605e6094565b6040518082815260200191505060405180910390f35b3415607e57600080fd5b60926004808035906020019091905050609a565b005b60005481565b806000819055507fa32bc18230dd172221ac5c4821a5f1f1a831f27b1396d244cdd891c58f132435816040518082815260200191505060405180910390a1505600a165627a7a72305820b648c68bc68fb31b11c40305c410b178eb7295c16f641511e8a5f6b0a9d65f650029","sourceMap":"26:265:0:-;;;113:74;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;174:6;166:5;:14;;;;113:74;26:265;;;;;;","deployedSourceMap":"26:265:0:-;;;;;;;;;;;;;;;;;;;;;;;;;;;;;55:17;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;194:95;;;;;;;;;;;;;;;;;;;;;;;;;;55:17;;;;:::o;194:95::-;250:6;242:5;:14;;;;266:16;275:6;266:16;;;;;;;;;;;;;;;;;;194:95;:::o","source":"pragma solidity ^0.4.15;\n\ncontract SimpleStorage {\n uint public count;\n\n event CountSet(uint _count);\n\n function SimpleStorage(uint _count) public {\n count = _count;\n } \n\n function setCount(uint _count) public {\n count = _count;\n CountSet(_count);\n }\n}\n","sourcePath":"/Users/martyall/code/foam/foam.contracts.deux/contracts/SimpleStorage.sol","ast":{"attributes":{"absolutePath":"/Users/martyall/code/foam/foam.contracts.deux/contracts/SimpleStorage.sol","exportedSymbols":{"SimpleStorage":[32]}},"children":[{"attributes":{"literals":["solidity","^","0.4",".15"]},"id":1,"name":"PragmaDirective","src":"0:24:0"},{"attributes":{"baseContracts":[null],"contractDependencies":[null],"contractKind":"contract","documentation":null,"fullyImplemented":true,"linearizedBaseContracts":[32],"name":"SimpleStorage","scope":33},"children":[{"attributes":{"constant":false,"name":"count","scope":32,"stateVariable":true,"storageLocation":"default","type":"uint256","value":null,"visibility":"public"},"children":[{"attributes":{"name":"uint","type":"uint256"},"id":2,"name":"ElementaryTypeName","src":"55:4:0"}],"id":3,"name":"VariableDeclaration","src":"55:17:0"},{"attributes":{"anonymous":false,"name":"CountSet"},"children":[{"children":[{"attributes":{"constant":false,"indexed":false,"name":"_count","scope":7,"stateVariable":false,"storageLocation":"default","type":"uint256","value":null,"visibility":"internal"},"children":[{"attributes":{"name":"uint","type":"uint256"},"id":4,"name":"ElementaryTypeName","src":"94:4:0"}],"id":5,"name":"VariableDeclaration","src":"94:11:0"}],"id":6,"name":"ParameterList","src":"93:13:0"}],"id":7,"name":"EventDefinition","src":"79:28:0"},{"attributes":{"constant":false,"implemented":true,"isConstructor":true,"modifiers":[null],"name":"SimpleStorage","payable":false,"scope":32,"stateMutability":"nonpayable","superFunction":null,"visibility":"public"},"children":[{"children":[{"attributes":{"constant":false,"name":"_count","scope":17,"stateVariable":false,"storageLocation":"default","type":"uint256","value":null,"visibility":"internal"},"children":[{"attributes":{"name":"uint","type":"uint256"},"id":8,"name":"ElementaryTypeName","src":"136:4:0"}],"id":9,"name":"VariableDeclaration","src":"136:11:0"}],"id":10,"name":"ParameterList","src":"135:13:0"},{"attributes":{"parameters":[null]},"children":[],"id":11,"name":"ParameterList","src":"156:0:0"},{"children":[{"children":[{"attributes":{"argumentTypes":null,"isConstant":false,"isLValue":false,"isPure":false,"lValueRequested":false,"operator":"=","type":"uint256"},"children":[{"attributes":{"argumentTypes":null,"overloadedDeclarations":[null],"referencedDeclaration":3,"type":"uint256","value":"count"},"id":12,"name":"Identifier","src":"166:5:0"},{"attributes":{"argumentTypes":null,"overloadedDeclarations":[null],"referencedDeclaration":9,"type":"uint256","value":"_count"},"id":13,"name":"Identifier","src":"174:6:0"}],"id":14,"name":"Assignment","src":"166:14:0"}],"id":15,"name":"ExpressionStatement","src":"166:14:0"}],"id":16,"name":"Block","src":"156:31:0"}],"id":17,"name":"FunctionDefinition","src":"113:74:0"},{"attributes":{"constant":false,"implemented":true,"isConstructor":false,"modifiers":[null],"name":"setCount","payable":false,"scope":32,"stateMutability":"nonpayable","superFunction":null,"visibility":"public"},"children":[{"children":[{"attributes":{"constant":false,"name":"_count","scope":31,"stateVariable":false,"storageLocation":"default","type":"uint256","value":null,"visibility":"internal"},"children":[{"attributes":{"name":"uint","type":"uint256"},"id":18,"name":"ElementaryTypeName","src":"212:4:0"}],"id":19,"name":"VariableDeclaration","src":"212:11:0"}],"id":20,"name":"ParameterList","src":"211:13:0"},{"attributes":{"parameters":[null]},"children":[],"id":21,"name":"ParameterList","src":"232:0:0"},{"children":[{"children":[{"attributes":{"argumentTypes":null,"isConstant":false,"isLValue":false,"isPure":false,"lValueRequested":false,"operator":"=","type":"uint256"},"children":[{"attributes":{"argumentTypes":null,"overloadedDeclarations":[null],"referencedDeclaration":3,"type":"uint256","value":"count"},"id":22,"name":"Identifier","src":"242:5:0"},{"attributes":{"argumentTypes":null,"overloadedDeclarations":[null],"referencedDeclaration":19,"type":"uint256","value":"_count"},"id":23,"name":"Identifier","src":"250:6:0"}],"id":24,"name":"Assignment","src":"242:14:0"}],"id":25,"name":"ExpressionStatement","src":"242:14:0"},{"children":[{"attributes":{"argumentTypes":null,"isConstant":false,"isLValue":false,"isPure":false,"isStructConstructorCall":false,"lValueRequested":false,"names":[null],"type":"tuple()","type_conversion":false},"children":[{"attributes":{"argumentTypes":[{"typeIdentifier":"t_uint256","typeString":"uint256"}],"overloadedDeclarations":[null],"referencedDeclaration":7,"type":"function (uint256)","value":"CountSet"},"id":26,"name":"Identifier","src":"266:8:0"},{"attributes":{"argumentTypes":null,"overloadedDeclarations":[null],"referencedDeclaration":19,"type":"uint256","value":"_count"},"id":27,"name":"Identifier","src":"275:6:0"}],"id":28,"name":"FunctionCall","src":"266:16:0"}],"id":29,"name":"ExpressionStatement","src":"266:16:0"}],"id":30,"name":"Block","src":"232:57:0"}],"id":31,"name":"FunctionDefinition","src":"194:95:0"}],"id":32,"name":"ContractDefinition","src":"26:265:0"}],"id":33,"name":"SourceUnit","src":"0:292:0"},"compiler":{"name":"solc","version":"0.4.18+commit.9cf6e910.Emscripten.clang"},"networks":{"420123":{"address":"0x84830d0e4d69d79f45e5b32000dc45159df91442"}},"schemaVersion":"1.0.1","updatedAt":"2018-03-20T17:42:03.220Z"}
22 changes: 13 additions & 9 deletions src/Deploy.purs
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,15 @@ import Data.Either (Either(..), either)
import Data.Foreign.NullOrUndefined (unNullOrUndefined)
import Data.Lens ((^?), (?~), (.~))
import Data.Lens.Index (ix)
import Data.Maybe (Maybe(..), maybe)
import Data.Maybe (Maybe, maybe, isNothing, fromJust)
import Network.Ethereum.Web3 (ETH, Web3, Address, BigNumber, HexString, mkHexString, defaultTransactionOptions, _from, _data, fromWei, _value, runWeb3, mkAddress)
import Network.Ethereum.Web3.Api (eth_sendTransaction)
import Network.Ethereum.Web3.Types.Provider (Provider)
import Data.Newtype (unwrap)
import Node.Encoding (Encoding(UTF8))
import Node.FS.Aff (FS, readTextFile, writeTextFile)
import Node.Path (FilePath)
import Partial.Unsafe (unsafePartial)
import Utils (withTimeout, pollTransactionReceipt, reportIfErrored)
import Types (DeployConfig, ContractConfig)

Expand Down Expand Up @@ -103,17 +104,20 @@ getPublishedContractAddress
getPublishedContractAddress txHash provider name = do
C.log $ "Polling for TransactionReceipt: " <> show txHash
etxReceipt <- attempt $ withTimeout (Milliseconds $ 90.0 * 1000.0) (pollTransactionReceipt txHash provider)
case unNullOrUndefined <<< _.contractAddress <<< unwrap <$> etxReceipt of
case unwrap <$> etxReceipt of
Left err -> do
liftAff $ C.error $ "No Transaction Receipt found for deployment : " <> name <> " : " <> show txHash
liftAff $ throwError err
Right Nothing -> do
let missingMessage = "Didn't find contract address in Transaction Receipt for deployment: " <> name
liftAff $ C.error missingMessage
liftAff $ liftEff' $ throw missingMessage
Right (Just contractAddress) -> do
liftAff <<< C.log $ "Contract " <> name <> " deployed to address " <> show contractAddress
pure contractAddress
Right txReceipt ->
if txReceipt.status == "0x0" || isNothing (unNullOrUndefined txReceipt.contractAddress)
then do
let missingMessage = "Deployment failed to create contract, no address found or status 0x0 in receipt: " <> name
liftAff $ C.error missingMessage
liftAff $ liftEff' $ throw missingMessage
else do
let contractAddress = unsafePartial fromJust <<< unNullOrUndefined $ txReceipt.contractAddress
liftAff <<< C.log $ "Contract " <> name <> " deployed to address " <> show contractAddress
pure contractAddress

-- | `deployContractNoArgs` grabs the bytecode from a build artifact and deploys it
-- | from the primary account, writing the contract address to the artifact.
Expand Down
9 changes: 7 additions & 2 deletions src/Main.purs
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,11 @@ import Control.Monad.Aff (launchAff)
import Control.Monad.Eff (Eff)
import Control.Monad.Eff.Console (CONSOLE)
import Data.Lens ((?~))
import Network.Ethereum.Web3 (ETH, defaultTransactionOptions, _from)
import Data.Maybe (fromJust)
import Network.Ethereum.Web3 (ETH, defaultTransactionOptions, _from, _gas)
import Network.Ethereum.Web3.Types.BigNumber (parseBigNumber, decimal)
import Node.FS.Aff (FS)
import Partial.Unsafe (unsafePartial)

import Contracts.SimpleStorage as SimpleStorage

Expand All @@ -17,6 +20,8 @@ import ContractConfig (simpleStorageConfig)
main :: forall e. Eff (eth :: ETH, console :: CONSOLE, fs :: FS | e) Unit
main = void <<< launchAff $ do
cfg <- makeDeployConfig
let txOpts = defaultTransactionOptions # _from ?~ cfg.primaryAccount
let bigGasLimit = unsafePartial fromJust $ parseBigNumber decimal "900000"
txOpts = defaultTransactionOptions # _from ?~ cfg.primaryAccount
# _gas ?~ bigGasLimit
_ <- deployContractWithArgs cfg simpleStorageConfig $ SimpleStorage.constructor txOpts
pure unit
16 changes: 14 additions & 2 deletions test/Main.purs
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,29 @@ module Test.Main where

import Prelude
import Control.Monad.Aff (launchAff)
import Control.Monad.Aff.AVar (AVAR)
import Control.Monad.Aff.Console (CONSOLE)
import Control.Monad.Eff (Eff)
import Control.Monad.Eff.Class (liftEff)
import Data.Maybe (Maybe(..))
import Test.Spec.Reporter.Console (consoleReporter)
import Test.Spec.Runner (run', defaultConfig)
import Test.Spec.Runner (PROCESS, run', defaultConfig)
import Network.Ethereum.Web3 (ETH)
import Node.FS.Aff (FS)

import Utils (makeDeployConfig)

import SimpleStorageSpec (simpleStorageSpec)

main :: Eff _ Unit
main
:: forall e.
Eff ( console :: CONSOLE
, eth :: ETH
, avar :: AVAR
, fs :: FS
, process :: PROCESS
| e
) Unit
main = void <<< launchAff $ do
deployConfig <- makeDeployConfig
liftEff $ run' defaultConfig {timeout = Just (60 * 1000)} [consoleReporter] do
Expand Down
Loading

0 comments on commit 12b1f29

Please sign in to comment.