Skip to content

Commit

Permalink
Merge PR #178: Replace orchestrator with gorc in integration tests
Browse files Browse the repository at this point in the history
* orchestrator to gorc

* create gorc config and mount startup script

* error check

* update sdk

* path

* path

* dir fix

* mount on working dir

* double input

* remove cruft

* no more startup script
  • Loading branch information
mvid authored Sep 5, 2021
1 parent 8af32db commit 490da01
Show file tree
Hide file tree
Showing 8 changed files with 104 additions and 46 deletions.
14 changes: 13 additions & 1 deletion module/cmd/gravity/cmd/root_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,12 @@ import (
"strings"
"testing"

"github.com/cosmos/cosmos-sdk/client"
"github.com/cosmos/cosmos-sdk/client/flags"
"github.com/cosmos/cosmos-sdk/client/keys"
"github.com/cosmos/cosmos-sdk/crypto/hd"
"github.com/cosmos/cosmos-sdk/crypto/keyring"
"github.com/spf13/cobra"
"github.com/stretchr/testify/require"
"github.com/tendermint/tendermint/libs/cli"
)
Expand All @@ -24,6 +26,13 @@ type KeyOutput struct {
func TestKeyGen(t *testing.T) {
mnemonic := "weasel lunch attack blossom tone drum unfair worry risk level negative height sight nation inside task oyster client shiver aware neck mansion gun dune"

input := strings.NewReader(mnemonic + "\n")
initClientCtx := client.Context{}.
WithHomeDir("/foo/bar").
WithChainID("test-chain").
WithKeyringDir("/foo/bar").
WithInput(input)

// generate key from binary
keyCmd := keys.AddKeyCommand()
keyCmd.Flags().String(cli.OutputFlag, "json", "output flag")
Expand All @@ -34,7 +43,10 @@ func TestKeyGen(t *testing.T) {
"--recover=true",
"orch",
})
keyCmd.SetIn(strings.NewReader(mnemonic + "\n"))
keyCmd.PreRunE = func(cmd *cobra.Command, args []string) error {
return client.SetCmdClientContextHandler(initClientCtx, keyCmd)
}
keyCmd.SetIn(input)

buf := bytes.NewBuffer(nil)
keyCmd.SetOut(buf)
Expand Down
8 changes: 3 additions & 5 deletions orchestrator/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
# Reference: https://www.lpalmieri.com/posts/fast-rust-docker-builds/

FROM rust:1.52 as cargo-chef-rust
RUN apt-get install bash
RUN cargo install cargo-chef

FROM cargo-chef-rust as planner
Expand All @@ -24,10 +23,9 @@ COPY . .
# Copy over the cached dependencies
COPY --from=cacher /app/target target
COPY --from=cacher /usr/local/cargo /usr/local/cargo
RUN cargo build --release --bin orchestrator
RUN cargo build --release --bin gorc

FROM cargo-chef-rust as runtime
WORKDIR app
COPY startup.sh startup.sh
COPY --from=builder /app/target/release/orchestrator /usr/local/bin
CMD sh startup.sh
COPY --from=builder /app/target/release/gorc /usr/local/bin
CMD gorc
6 changes: 0 additions & 6 deletions orchestrator/ci.Dockerfile

This file was deleted.

24 changes: 0 additions & 24 deletions orchestrator/startup.sh

This file was deleted.

2 changes: 1 addition & 1 deletion testnet/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ require (
github.com/Microsoft/go-winio v0.5.0 // indirect
github.com/cenkalti/backoff/v4 v4.1.1 // indirect
github.com/containerd/continuity v0.1.0 // indirect
github.com/cosmos/cosmos-sdk v0.43.0
github.com/cosmos/cosmos-sdk v0.44.0
github.com/cosmos/go-bip39 v1.0.0
github.com/ethereum/go-ethereum v1.9.25
github.com/matttproud/golang_protobuf_extensions v1.0.2-0.20181231171920-c182affec369 // indirect
Expand Down
2 changes: 2 additions & 0 deletions testnet/go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,8 @@ github.com/coreos/pkg v0.0.0-20160727233714-3ac0863d7acf/go.mod h1:E3G3o1h8I7cfc
github.com/coreos/pkg v0.0.0-20180928190104-399ea9e2e55f/go.mod h1:E3G3o1h8I7cfcXa63jLwjI0eiQQMgzzUDFVpN/nH/eA=
github.com/cosmos/cosmos-sdk v0.43.0 h1:l2GXJMDVtJyHb35pDUCw+uyr6eZtBo8vt+7PSsq+Fjo=
github.com/cosmos/cosmos-sdk v0.43.0/go.mod h1:ctcrTEAhei9s8O3KSNvL0dxe+fVQGp07QyRb/7H9JYE=
github.com/cosmos/cosmos-sdk v0.44.0 h1:eOSjACNtTnThEJ62IsS+pMm3OIU6hgMVqrp4TZClLZo=
github.com/cosmos/cosmos-sdk v0.44.0/go.mod h1:orG0jzFJ2KsDfzLd/X0JSOMzF4Oxc/BQz2GkcYF4gRE=
github.com/cosmos/go-bip39 v0.0.0-20180819234021-555e2067c45d/go.mod h1:tSxLoYXyBmiFeKpvmq4dzayMdCjCnu8uqmCysIGBT2Y=
github.com/cosmos/go-bip39 v1.0.0 h1:pcomnQdrdH22njcAatO0yWojsUnCO3y2tNoV1cb6hHY=
github.com/cosmos/go-bip39 v1.0.0/go.mod h1:RNJv0H/pOIVgxw6KS7QeX2a0Uo0aKUlfhZ4xuwvCdJw=
Expand Down
12 changes: 12 additions & 0 deletions testnet/gorc_test_bootstrap.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
#!/busybox/sh

set -ex

# import orchestrator Sommelier key
gorc --config=/root/gorc/config.toml keys cosmos recover orch-key "$ORCH_MNEMONIC"

# import orchestrator Ethereum key
gorc --config=/root/gorc/config.toml keys eth import orch-eth-key $ETH_PRIV_KEY

# start gorc orchestrator
gorc --config=/root/gorc/config.toml orchestrator start --cosmos-key=orch-key --ethereum-key=orch-eth-key
82 changes: 73 additions & 9 deletions testnet/with_pristine_e2e_environment_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,10 @@ import (
"bytes"
"encoding/json"
"fmt"
"io"
"io/fs"
"os"
"path"
"path/filepath"
"strings"
"testing"
Expand Down Expand Up @@ -327,16 +329,44 @@ func withPristineE2EEnvironment(t *testing.T, cb func(
// deploy orchestrators
for _, orchestrator := range chain.Orchestrators {
validator := chain.Validators[orchestrator.Index]
gorcConfig := fmt.Sprintf(`keystore = "/root/gorc/keystore/"
[gravity]
contract = "%s"
fees_denom = "%s"
[ethereum]
key_derivation_path = "m/44'/60'/0'/0/0"
rpc = "http://%s:8545"
[cosmos]
key_derivation_path = "m/44'/118'/0'/0/0"
grpc = "http://%s:9090"
gas_price = { amount = %s, denom = "%s" }
prefix = "gravity"
`,
gravityContract,
"stake",
"ethereum",
validator.instanceName(),
"0.0001",
"stake",
)

gorcConfigPath := filepath.Join(wd, chain.DataDir, chain.ID, orchestrator.instanceName(), "gorc")
err = os.MkdirAll(gorcConfigPath, 0755)
require.NoError(t, err, "error creating gorc config dir")
filePath := path.Join(gorcConfigPath, "config.toml")
writeFile(t, filePath, []byte(gorcConfig))
_, err := copyFile(
filepath.Join("./", "testnet", "gorc_test_bootstrap.sh"),
filepath.Join(gorcConfigPath, "gorc_test_bootstrap.sh"),
)
require.NoError(t, err, "error copying bootstrap file")

env := []string{
fmt.Sprintf("VALIDATOR=%s", validator.instanceName()),
fmt.Sprintf("COSMOS_GRPC=http://%s:9090/", validator.instanceName()),
fmt.Sprintf("COSMOS_RPC=http://%s:1317", validator.instanceName()),
fmt.Sprintf("VALIDATOR=%s", validator.instanceName()),
fmt.Sprintf("COSMOS_PHRASE=%s", orchestrator.Mnemonic),
fmt.Sprintf("ETH_PRIVATE_KEY=%s", validator.EthereumKey.PrivateKey),
fmt.Sprintf("CONTRACT_ADDR=%s", gravityContract),
"DENOM=stake",
"ETH_RPC=http://ethereum:8545",
fmt.Sprintf("ORCH_MNEMONIC=%s", orchestrator.Mnemonic),
fmt.Sprintf("ETH_PRIV_KEY=%s", validator.EthereumKey.PrivateKey),
"RUST_BACKTRACE=full",
}
runOpts := &dockertest.RunOptions{
Expand All @@ -345,6 +375,14 @@ func withPristineE2EEnvironment(t *testing.T, cb func(
Repository: "orchestrator",
Tag: "prebuilt",
Env: env,
Mounts: []string{
fmt.Sprintf("%s/:/root/gorc", gorcConfigPath),
},
Entrypoint: []string{
"sh",
"-c",
"chmod +x /root/gorc/gorc_bootstrap.sh && /root/gorc/gorc_bootstrap.sh",
},
}

resource, err := pool.RunWithOptions(runOpts, noRestart)
Expand Down Expand Up @@ -378,3 +416,29 @@ func noRestart(config *docker.HostConfig) {
Name: "no",
}
}

func copyFile(src, dst string) (int64, error) {
sourceFileStat, err := os.Stat(src)
if err != nil {
return 0, err
}

if !sourceFileStat.Mode().IsRegular() {
return 0, fmt.Errorf("%s is not a regular file", src)
}

source, err := os.Open(src)
if err != nil {
return 0, err
}
defer source.Close()

destination, err := os.Create(dst)
if err != nil {
return 0, err
}
defer destination.Close()

nBytes, err := io.Copy(destination, source)
return nBytes, err
}

0 comments on commit 490da01

Please sign in to comment.