Skip to content

Commit

Permalink
tests: add check-prep
Browse files Browse the repository at this point in the history
  • Loading branch information
pro-wh committed Aug 4, 2020
1 parent cb157bd commit bdd4436
Show file tree
Hide file tree
Showing 3 changed files with 88 additions and 1 deletion.
3 changes: 3 additions & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,11 @@ go 1.14
replace github.com/tendermint/tendermint => github.com/oasisprotocol/tendermint v0.33.4-oasis2

require (
github.com/coinbase/rosetta-cli v0.4.0
github.com/coinbase/rosetta-sdk-go v0.3.3
github.com/dgraph-io/badger v1.6.1
github.com/oasisprotocol/ed25519 v0.0.0-20200528083105-55566edd6df0
github.com/oasisprotocol/oasis-core/go v0.0.0-20200702171459-20d1a2dc6b66
github.com/vmihailenco/msgpack/v5 v5.0.0-beta.1
google.golang.org/grpc v1.29.1
)
83 changes: 83 additions & 0 deletions tests/check-prep/main.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
package main

import (
"bytes"
"context"
"fmt"
"io/ioutil"
"os"
"path"

"github.com/coinbase/rosetta-cli/configuration"
"github.com/coinbase/rosetta-sdk-go/client"
"github.com/coinbase/rosetta-sdk-go/keys"
"github.com/coinbase/rosetta-sdk-go/types"
"github.com/dgraph-io/badger"
"github.com/vmihailenco/msgpack/v5"

"github.com/oasisprotocol/oasis-core-rosetta-gateway/services"
"github.com/oasisprotocol/oasis-core-rosetta-gateway/tests/common"
)

func main() {
// Create a configuration file for the local testnet.
config := configuration.DefaultConfiguration()

rc := client.NewAPIClient(client.NewConfiguration("http://localhost:8080", "rosetta-sdk-go", nil))
nlr, re, err := rc.NetworkAPI.NetworkList(context.Background(), &types.MetadataRequest{})
if err != nil {
panic(err)
}
if re != nil {
panic(re)
}
if len(nlr.NetworkIdentifiers) != 1 {
panic("len(nlr.NetworkIdentifiers)")
}
fmt.Println("network identifiers", common.DumpJSON(nlr.NetworkIdentifiers))
config.Network = nlr.NetworkIdentifiers[0]

config.DataDirectory = "/tmp/rosetta-cli-oasistests"

config.Construction.Currency = services.OasisCurrency
config.Construction.CurveType = types.Edwards25519

if err := ioutil.WriteFile("rosetta-cli-config.json", []byte(common.DumpJSON(config)), 0o666); err != nil {
panic(err)
}

// Create an account for construction tests.
testEntityAddress, testEntityKeyPair := common.TestEntity()

constructionStorePath := path.Join(config.DataDirectory, "check-construction", types.Hash(config.Network))
if err := os.MkdirAll(constructionStorePath, 0o777); err != nil {
panic(err)
}
db, err := badger.Open(badger.DefaultOptions(constructionStorePath))
if err != nil {
panic(err)
}
if err := db.Update(func(txn *badger.Txn) error {
key := struct {
Address string `json:"address"`
KeyPair *keys.KeyPair `json:"keypair"`
}{testEntityAddress, testEntityKeyPair}
var keyBuf bytes.Buffer
enc := msgpack.GetEncoder()
enc.Reset(&keyBuf)
enc.UseJSONTag(true)
if err := enc.Encode(&key); err != nil {
panic(err)
}
msgpack.PutEncoder(enc)
if err := txn.Set([]byte("key/"+testEntityAddress), keyBuf.Bytes()); err != nil {
panic(err)
}
return nil
}); err != nil {
panic(err)
}
if err := db.Close(); err != nil {
panic(err)
}
}
3 changes: 2 additions & 1 deletion tests/test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,8 @@ ${OASIS_ROSETTA_GW} &
sleep 3

printf "${GRN}### Validating Rosetta gateway implementation...${OFF}\n"
./rosetta-cli check:data --end 42
go run ./check-prep
./rosetta-cli --configuration-file rosetta-cli-config.json check:data --end 42
rm -rf "${ROOT}/validator-data" /tmp/rosetta-cli*

printf "${GRN}### Testing construction signing workflow...${OFF}\n"
Expand Down

0 comments on commit bdd4436

Please sign in to comment.