Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Nameservice interact #168

Closed
wants to merge 21 commits into from
Closed
Changes from 1 commit
Commits
Show all changes
21 commits
Select commit Hold shift + click to select a range
243d621
Init hs-abci-test-utils
IvantheTricourne Dec 12, 2019
2b4f8f2
import packages and use correct default extensions
IvantheTricourne Dec 12, 2019
f66e856
use directory module hierarchy
IvantheTricourne Dec 12, 2019
2a6b3c3
update project files with new utils lib
IvantheTricourne Dec 12, 2019
5eca207
nameservice tests passing
IvantheTricourne Dec 12, 2019
b1e7680
use utils in ss
IvantheTricourne Dec 12, 2019
ffa8c9a
use new user module in nameservice tests
IvantheTricourne Dec 12, 2019
7c00708
delete special msg encoder
IvantheTricourne Dec 12, 2019
12d2319
use user util module in simple storage tests
IvantheTricourne Dec 13, 2019
e17127d
move response checkers to utils library
IvantheTricourne Dec 13, 2019
05bfd1d
move request runners to new request module
IvantheTricourne Dec 13, 2019
e04471e
Update readme
IvantheTricourne Dec 16, 2019
74b2788
Merge branch 'master' of github.com:f-o-a-m/hs-abci into hs-abci-test…
IvantheTricourne Jan 2, 2020
776d1ed
Add interact exe to nameservice
IvantheTricourne Jan 2, 2020
04270a7
Add basic main for interact
IvantheTricourne Jan 2, 2020
298656f
add random name generator
IvantheTricourne Jan 2, 2020
eba7e74
Clean up action type signatures
IvantheTricourne Jan 2, 2020
77192d7
Add sleep
IvantheTricourne Jan 3, 2020
a8c3dca
Merge branch 'master' into nameservice-interact
IvantheTricourne Jan 3, 2020
bff75c4
Add ability to generate multiple txs from an action
IvantheTricourne Jan 6, 2020
9aee76f
Merge branch 'nameservice-interact' of github.com:f-o-a-m/hs-abci int…
IvantheTricourne Jan 6, 2020
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
use new user module in nameservice tests
  • Loading branch information
IvantheTricourne committed Dec 12, 2019
commit ffa8c9ac94a614c5383abf2bcc1edca1de1c5cda
29 changes: 1 addition & 28 deletions hs-abci-examples/nameservice/test/Nameservice/Test/E2ESpec.hs
Original file line number Diff line number Diff line change
@@ -56,6 +56,7 @@ import Tendermint.Utils.Client (ClientResponse (..),
HasClient (..),
RunClient (..))
import Tendermint.Utils.Events (FromEvent (..))
import Tendermint.Utils.User (User (..), makeUser, mkSignedRawTransactionWithRoute)
import Test.Hspec

spec :: Spec
@@ -291,37 +292,12 @@ encodeRawTx = Base64.fromBytes . encode
encodeMsgData :: Message a => a -> BS.ByteString
encodeMsgData = BL.toStrict . toLazyByteString

-- sign a trx with a user's private key
mkSignedRawTransactionWithRoute :: Message a => BS.ByteString -> SecKey -> a -> RawTransaction
mkSignedRawTransactionWithRoute route privateKey msg = sign unsigned
where unsigned = RawTransaction { rawTransactionData = encodeMsgData msg
, rawTransactionRoute = cs route
, rawTransactionSignature = ""
}
sig = signRawTransaction algProxy privateKey unsigned
sign rt = rt { rawTransactionSignature = encodeCompactRecSig $ exportCompactRecSig sig }

data User = User
{ userPrivKey :: SecKey
, userAddress :: Address
}

user1 :: User
user1 = makeUser "f65255094d7773ed8dd417badc9fc045c1f80fdc5b2d25172b031ce6933e039a"

user2 :: User
user2 = makeUser "f65242094d7773ed8dd417badc9fc045c1f80fdc5b2d25172b031ce6933e039a"

makeUser :: String -> User
makeUser privKeyStr =
let privateKey = fromJust . secKey . Hex.toBytes . fromString $ privKeyStr
pubKey = derivePubKey privateKey
address = addressFromPubKey (Proxy @Secp256k1) pubKey
in User privateKey address

algProxy :: Proxy Secp256k1
algProxy = Proxy

--------------------------------------------------------------------------------

getWhois :: QueryArgs Name -> RPC.TendermintM (ClientResponse Whois)
@@ -332,6 +308,3 @@ apiP = Proxy

(getBalance :<|> getWhois) =
genClient (Proxy :: Proxy RPC.TendermintM) apiP def

encodeCompactRecSig :: CompactRecSig -> ByteString
encodeCompactRecSig (CompactRecSig r s v) = snoc (fromShort r <> fromShort s) v
1 change: 0 additions & 1 deletion hs-abci-sdk/package.yaml
Original file line number Diff line number Diff line change
@@ -59,7 +59,6 @@ dependencies:
- exceptions
- hs-abci-types
- hs-abci-server
- hs-tendermint-client
- http-types
- katip
- lens
1 change: 1 addition & 0 deletions hs-abci-test-utils/package.yaml
Original file line number Diff line number Diff line change
@@ -25,6 +25,7 @@ dependencies:
- errors
- lens
- mtl
- secp256k1-haskell
- servant
- string-conversions
- text
46 changes: 46 additions & 0 deletions hs-abci-test-utils/src/Tendermint/Utils/User.hs
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
module Tendermint.Utils.User where

import Crypto.Secp256k1 (CompactRecSig (..), SecKey,
derivePubKey,
exportCompactRecSig, secKey)
import qualified Data.ByteArray.HexString as Hex
import Data.ByteString (ByteString, snoc)
import qualified Data.ByteString as BS
import Data.ByteString.Short (fromShort)
import Data.Maybe (fromJust)
import Data.Proxy
import Data.String (fromString)
import Data.String.Conversions (cs)
import Tendermint.SDK.Codec (HasCodec (..))
import Tendermint.SDK.Crypto (Secp256k1, addressFromPubKey)
import Tendermint.SDK.Types.Address (Address (..))
import Tendermint.SDK.Types.Transaction (RawTransaction (..),
signRawTransaction)

data User = User
{ userPrivKey :: SecKey
, userAddress :: Address
}

makeUser :: String -> User
makeUser privKeyStr =
let privateKey = fromJust . secKey . Hex.toBytes . fromString $ privKeyStr
pubKey = derivePubKey privateKey
address = addressFromPubKey (Proxy @Secp256k1) pubKey
in User privateKey address

algProxy :: Proxy Secp256k1
algProxy = Proxy

-- sign a trx with a user's private key
mkSignedRawTransactionWithRoute :: HasCodec a => BS.ByteString -> SecKey -> a -> RawTransaction
mkSignedRawTransactionWithRoute route privateKey msg = sign unsigned
where unsigned = RawTransaction { rawTransactionData = encode msg
, rawTransactionRoute = cs route
, rawTransactionSignature = ""
}
sig = signRawTransaction algProxy privateKey unsigned
sign rt = rt { rawTransactionSignature = encodeCompactRecSig $ exportCompactRecSig sig }

encodeCompactRecSig :: CompactRecSig -> ByteString
encodeCompactRecSig (CompactRecSig r s v) = snoc (fromShort r <> fromShort s) v