@@ -2,10 +2,19 @@ module CoreSpec.BigNumber (bigNumberSpec) where
22
33
44import Prelude
5- import Data.Maybe (Maybe (Just))
5+
6+ import Control.Monad.Except (runExcept )
7+ import Data.Argonaut as A
8+ import Data.Either (Either (..), fromRight )
9+ import Data.Foreign (toForeign )
10+ import Data.Foreign.Class (decode , encode )
11+ import Data.Maybe (Maybe (Just), fromJust )
12+ import Network.Ethereum.Core.BigNumber (BigNumber , decimal , embed , hexadecimal , parseBigNumber )
13+ import Partial.Unsafe (unsafePartial )
14+ import Simple.JSON (readImpl )
615import Test.Spec (Spec , describe , it )
716import Test.Spec.Assertions (shouldEqual )
8- import Network.Ethereum.Core.BigNumber ( BigNumber , decimal , embed , hexadecimal , parseBigNumber )
17+
918
1019bigNumberSpec :: forall r . Spec r Unit
1120bigNumberSpec = describe " BigNumber-spec" do
@@ -47,3 +56,15 @@ bigNumberSpec = describe "BigNumber-spec" do
4756 ((parseBigNumber decimal " 21" ) >>= \x -> pure $ x - zero) `shouldEqual` parseBigNumber hexadecimal " 0x15"
4857 (Just $ one `mul` one) `shouldEqual` parseBigNumber decimal " 1"
4958 (Just $ one * embed (-7 )) `shouldEqual` parseBigNumber hexadecimal " -0x7"
59+
60+ it " can handle deserialization" do
61+ let bnString = " f43"
62+ d1 = unsafePartial $ fromRight $ runExcept $ readImpl (toForeign bnString)
63+ d2 = unsafePartial $ fromRight $ runExcept $ decode (toForeign bnString)
64+ d3 = unsafePartial $ fromRight $ A .decodeJson (A .fromString bnString)
65+ d4 = unsafePartial $ fromJust $ parseBigNumber hexadecimal bnString
66+ d4 `shouldEqual` d1
67+ d4 `shouldEqual` d2
68+ d4 `shouldEqual` d3
69+ runExcept (decode (encode d1)) `shouldEqual` Right d4
70+ (A .decodeJson (A .encodeJson d1)) `shouldEqual` Right d4
0 commit comments