diff --git a/src/Network/Ethereum/Web3/Solidity/AbiEncoding.purs b/src/Network/Ethereum/Web3/Solidity/AbiEncoding.purs index 0bf97f9..b428488 100644 --- a/src/Network/Ethereum/Web3/Solidity/AbiEncoding.purs +++ b/src/Network/Ethereum/Web3/Solidity/AbiEncoding.purs @@ -22,12 +22,12 @@ import Data.ByteString (ByteString) import Data.ByteString (toUTF8, fromUTF8, length) as BS import Data.Either (Either) import Data.Functor.Tagged (Tagged, tagged, untagged) -import Data.Maybe (Maybe(..), fromJust, maybe) -import Data.String (codePointFromChar, dropWhile, splitAt) +import Data.Maybe (fromJust, maybe) +import Data.String (splitAt) import Data.Traversable (for, scanl) import Data.Tuple (Tuple(..)) import Data.Unfoldable (replicateA) -import Network.Ethereum.Core.BigNumber (fromString, fromStringAs, fromTwosComplement256, hexadecimal, toString, toTwosComplement256, unsafeToInt) +import Network.Ethereum.Core.BigNumber (fromString, fromTwosComplement256, toString, toTwosComplement256, unsafeToInt) import Network.Ethereum.Core.HexString (HexString, PadByte(..), fromByteString, mkHexString, numberOfBytes, padLeft, padRight, toByteString, unHex) import Network.Ethereum.Types (Address, BigNumber, embed, mkAddress, unAddress) import Network.Ethereum.Web3.Solidity.Bytes (BytesN, unBytesN, update, proxyBytesN) @@ -38,7 +38,7 @@ import Network.Ethereum.Web3.Solidity.UInt (UIntN, unUIntN, uIntNFromBigNumber) import Network.Ethereum.Web3.Solidity.Vector (Vector, unVector) import Parsing (ParseError, Parser, ParseState(..), Position(..), ParserT, fail, getParserT, stateParserT, runParser) import Parsing.Combinators (lookAhead) -import Partial.Unsafe (unsafeCrashWith, unsafePartial) +import Partial.Unsafe (unsafePartial) import Type.Proxy (Proxy(..)) -- | Class representing values that have an encoding and decoding instance to/from a solidity type. @@ -212,12 +212,6 @@ instance abiDecodeTagged :: ABIDecode a => ABIDecode (Tagged s a) where -- | Special Builders and Parsers -------------------------------------------------------------------------------- -unsafeFromJust :: forall a. String -> Maybe a -> a -unsafeFromJust str a = - case a of - Just a' -> a' - Nothing -> unsafeCrashWith str - -- | base16 encode, then utf8 encode, then pad bytesBuilder :: ByteString -> HexString bytesBuilder = padRight Zero <<< fromByteString @@ -227,18 +221,15 @@ int256HexBuilder :: BigNumber -> HexString int256HexBuilder x = let a = toTwosComplement256 x - x' = unsafeFromJust ("int256HexBuilder " <> show a) $ mkHexString (toString a) + x' = unsafePartial $ fromJust $ mkHexString (toString a) in if x < zero then padLeft FF x' else padLeft Zero x' -- | Encode something that is essentially an unsigned integer. uInt256HexBuilder :: BigNumber -> HexString -uInt256HexBuilder x = - let - a = mkHexString $ toString x - in - padLeft Zero $ unsafeFromJust ("uInt256HexBuilder " <> show x) a +uInt256HexBuilder x = unsafePartial $ fromJust $ + padLeft Zero <$> mkHexString (toString x) -- | Parse as a signed `BigNumber` int256HexParser :: forall m. Monad m => ParserT HexString m BigNumber @@ -275,7 +266,7 @@ parseByte = do let { after, before } = splitAt 2 (unHex input) - mkHex s = maybe (fail $ "Unable to parse HexString: " <> s) pure $ mkHexString s + mkHex s = maybe (fail $ "Unable to parse bytes from hex: " <> s) pure $ mkHexString s position' = Position $ position { column = position.column + 1 } diff --git a/test/web3/Web3Spec/Encoding/ContainersSpec.purs b/test/web3/Web3Spec/Encoding/ContainersSpec.purs index 30ba0b4..241ff78 100644 --- a/test/web3/Web3Spec/Encoding/ContainersSpec.purs +++ b/test/web3/Web3Spec/Encoding/ContainersSpec.purs @@ -6,10 +6,9 @@ import Data.ByteString as BS import Data.Either (Either(..)) import Data.Generic.Rep (class Generic) import Data.Maybe (fromJust) -import Debug (spy) import Effect.Aff (Aff) import Effect.Class (liftEffect) -import Network.Ethereum.Web3.Solidity (BytesN, IntN, Tuple1(..), Tuple2(..), Tuple4(..), Tuple9(..), UIntN, fromByteString, intNFromBigNumber, nilVector, toDataBuilder, uIntNFromBigNumber, (:<)) +import Network.Ethereum.Web3.Solidity (BytesN, IntN, Tuple1(..), Tuple2(..), Tuple4(..), Tuple9(..), UIntN, fromByteString, intNFromBigNumber, nilVector, uIntNFromBigNumber, (:<)) import Network.Ethereum.Web3.Solidity.AbiEncoding (class ABIEncode, class ABIDecode, toDataBuilder, fromData) import Network.Ethereum.Web3.Solidity.Generic (genericFromData, genericABIEncode, class GenericABIDecode, class GenericABIEncode) import Network.Ethereum.Web3.Solidity.Sizes (s1, s16, s2, s224, s256, s4) @@ -17,16 +16,16 @@ import Network.Ethereum.Web3.Solidity.Vector (Vector, toVector) import Network.Ethereum.Web3.Types (Address, HexString, embed, mkAddress, mkHexString, unHex) import Parsing (ParseError) import Partial.Unsafe (unsafePartial) -import Test.QuickCheck (quickCheck, (), (===)) +import Test.QuickCheck (quickCheck, ()) import Test.Spec (Spec, describe, it) import Test.Spec.Assertions (shouldEqual) spec :: Spec Unit spec = describe "encoding-spec for containers" do - --staticArraysTests - --dynamicArraysTests - --tuplesTest + staticArraysTests + dynamicArraysTests + tuplesTest typePropertyTests roundTrip :: forall a. Show a => Eq a => ABIEncode a => ABIDecode a => a -> HexString -> Aff Unit