Skip to content

Commit

Permalink
setup local env in tests and cleanup scripts
Browse files Browse the repository at this point in the history
  • Loading branch information
calvwang9 committed Aug 14, 2023
1 parent 2299ce6 commit 36ee94b
Show file tree
Hide file tree
Showing 9 changed files with 94 additions and 108 deletions.
11 changes: 9 additions & 2 deletions integration-tests/common/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -122,18 +122,25 @@ Enabled = true
ChainID = '%s'
[[Cosmos.Nodes]]
Name = 'primary'
TendermintURL = '%s'
TendermintURL = 'http://host.docker.internal:26657'
[OCR2]
Enabled = true
[P2P]
[P2P.V1]
Enabled = false
[P2P.V2]
Enabled = true
DeltaDial = '5s'
DeltaReconcile = '5s'
ListenAddresses = ['0.0.0.0:6691']
`, chainID, nodeUrl)
[WebServer]
HTTPPort = 6688
[WebServer.TLS]
HTTPSPort = 0
`, chainID)
log.Debug().Str("toml", chainlinkConfig).Msg("Created chainlink config")

ttl := getTTL()
Expand Down
57 changes: 45 additions & 12 deletions integration-tests/ocr2_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"fmt"
"math/big"
"os"
"os/exec"
"strings"
"testing"
"time"
Expand All @@ -18,15 +19,15 @@ import (
"github.com/smartcontractkit/chainlink-cosmos/pkg/cosmos/params"
"github.com/smartcontractkit/chainlink-cosmos/pkg/cosmos/testutil"
relaylogger "github.com/smartcontractkit/chainlink-relay/pkg/logger"
"github.com/smartcontractkit/chainlink/integration-tests/actions"
// "github.com/smartcontractkit/chainlink/integration-tests/actions"
ocrtypes "github.com/smartcontractkit/libocr/offchainreporting2/types"

cometbfttypes "github.com/cometbft/cometbft/abci/types"
"github.com/cosmos/cosmos-sdk/types"
txtypes "github.com/cosmos/cosmos-sdk/types/tx"
banktypes "github.com/cosmos/cosmos-sdk/x/bank/types"
"github.com/stretchr/testify/require"
"go.uber.org/zap/zapcore"
// "go.uber.org/zap/zapcore"
)

func TestOCRBasic(t *testing.T) {
Expand All @@ -35,6 +36,23 @@ func TestOCRBasic(t *testing.T) {
commonConfig := common.NewCommon(t)
commonConfig.SetLocalEnvironment()

logger.Info().Msg("Starting wasmd container...")
err := exec.Command("../scripts/wasmd.sh").Run()
require.NoError(t, err, "Could not start wasmd container")
logger.Info().Msg("Starting postgres container...")
err = exec.Command("../scripts/postgres.sh").Run()
require.NoError(t, err, "Could not start postgres container")
logger.Info().Msg("Starting mock adapter...")
err = exec.Command("../scripts/mock-adapter.sh").Run()
require.NoError(t, err, "Could not start mock adapter")
logger.Info().Msg("Starting core nodes...")
cmd := exec.Command("../scripts/core.sh")
cmd.Env = os.Environ()
cmd.Env = append(cmd.Env, fmt.Sprintf("CL_CONFIG=%s", commonConfig.ChainlinkConfig))
err = cmd.Run()
require.NoError(t, err, "Could not start core nodes")
logger.Info().Msg("Set up local stack complete.")

params.InitCosmosSdk(
/* bech32Prefix= */ "wasm",
/* token= */ "cosm",
Expand Down Expand Up @@ -67,15 +85,15 @@ func TestOCRBasic(t *testing.T) {
msgSend := banktypes.NewMsgSend(testAccount, to, amount)
resp, err := cosmosClient.SignAndBroadcast([]types.Msg{msgSend}, accountNumber, sequenceNumber+uint64(i), gasPrice, privateKey, txtypes.BroadcastMode_BROADCAST_MODE_SYNC)
require.NoError(t, err, "Could not send tokens")
logger.Info().Str("txHash", resp.TxResponse.TxHash).Msg("Waiting for tx to be committed")
tx, success := client.AwaitTxCommitted(t, cosmosClient, resp.TxResponse.TxHash)
require.True(t, success)
require.Equal(t, cometbfttypes.CodeTypeOK, tx.TxResponse.Code)
logger.Info().Str("from", testAccount.String()).
Str("to", nodeAddr).
Str("amount", "10000000").
Str("token", "ucosm").
Msg("Sucessfully sent native tokens")
Str("txHash", resp.TxResponse.TxHash).
Msg("Sending native tokens")
tx, success := client.AwaitTxCommitted(t, cosmosClient, resp.TxResponse.TxHash)
require.True(t, success)
require.Equal(t, cometbfttypes.CodeTypeOK, tx.TxResponse.Code)
balance, err := cosmosClient.Balance(to, "ucosm")
require.NoError(t, err, "Could not fetch ucosm balance")
require.Equal(t, balance.String(), "10000000ucosm")
Expand Down Expand Up @@ -186,11 +204,26 @@ func TestOCRBasic(t *testing.T) {
err = validateRounds(t, cosmosClient, types.MustAccAddressFromBech32(ocrAddress), types.MustAccAddressFromBech32(ocrProxyAddress), commonConfig.IsSoak, commonConfig.TestDuration)
require.NoError(t, err, "Validating round should not fail")

t.Cleanup(func() {
err = actions.TeardownSuite(t, commonConfig.Env, "./", nil, nil, zapcore.DPanicLevel, nil)
//err = actions.TeardownSuite(t, t.Common.Env, utils.ProjectRoot, t.Cc.ChainlinkNodes, nil, zapcore.ErrorLevel)
require.NoError(t, err, "Error tearing down environment")
})
// Tear down local stack
logger.Info().Msg("Tearing down core nodes...")
err = exec.Command("../scripts/core.down.sh").Run()
require.NoError(t, err, "Could not tear down core nodes")
logger.Info().Msg("Tearing down mock adapter...")
err = exec.Command("../scripts/mock-adapter.down.sh").Run()
require.NoError(t, err, "Could not tear down mock adapter")
logger.Info().Msg("Tearing down postgres container...")
err = exec.Command("../scripts/postgres.down.sh").Run()
require.NoError(t, err, "Could not tear down postgres container")
logger.Info().Msg("Tearing down wasmd container...")
err = exec.Command("../scripts/wasmd.down.sh").Run()
require.NoError(t, err, "Could not tear down wasmd container")
logger.Info().Msg("Tear down local stack complete.")

// t.Cleanup(func() {
// err = actions.TeardownSuite(t, commonConfig.Env, "./", nil, nil, zapcore.DPanicLevel, nil)
// //err = actions.TeardownSuite(t, t.Common.Env, utils.ProjectRoot, t.Cc.ChainlinkNodes, nil, zapcore.ErrorLevel)
// require.NoError(t, err, "Error tearing down environment")
// })
}

func validateRounds(t *testing.T, cosmosClient *client.Client, ocrAddress types.AccAddress, ocrProxyAddress types.AccAddress, isSoak bool, testDuration time.Duration) error {
Expand Down
22 changes: 0 additions & 22 deletions scripts/config.toml

This file was deleted.

22 changes: 0 additions & 22 deletions scripts/config1.toml

This file was deleted.

22 changes: 0 additions & 22 deletions scripts/config2.toml

This file was deleted.

35 changes: 8 additions & 27 deletions scripts/core.sh
Original file line number Diff line number Diff line change
Expand Up @@ -11,36 +11,17 @@ container_version="2.3.0"
api_email="notreal@fakeemail.ch"
api_password="fj293fbBnlQ!f9vNs"

core_config="
[[Cosmos]]
Enabled = true
ChainID = 'testing'
[[Cosmos.Nodes]]
Name = 'primary'
TendermintURL = 'http://host.docker.internal:26657'
[OCR2]
Enabled = true
[P2P]
[P2P.V1]
Enabled = false
[P2P.V2]
Enabled = true
DeltaDial = '5s'
DeltaReconcile = '5s'
ListenAddresses = ['0.0.0.0:6691']
[WebServer]
HTTPPort = 6688
[WebServer.TLS]
HTTPSPort = 0
"
if [[ -z "${CL_CONFIG:-}" ]]; then
echo "No CL_CONFIG env var provided." >&2
exit 1
fi

platform_arg=""
if [ -n "${CORE_IMAGE:-}" ]; then
image_name="${CORE_IMAGE}"
else
image_name="smartcontract/chainlink:${container_version}"
platform_arg="--platform linux/amd64"
fi
echo "Using core image: ${image_name}"

Expand Down Expand Up @@ -80,9 +61,9 @@ for ((i = 1; i <= NODE_COUNT; i++)); do
--rm \
-d \
--add-host=host.docker.internal:host-gateway \
--platform linux/amd64 \
$platform_arg \
"${listen_args[@]}" \
-e "CL_CONFIG=${core_config}" \
-e "CL_CONFIG=${CL_CONFIG}" \
-e "CL_DATABASE_URL=postgresql://postgres:postgres@host.docker.internal:5432/${database_name}?sslmode=disable" \
-e 'CL_PASSWORD_KEYSTORE=asdfasdfasdfasdf' \
--name "${container_name}.$i" \
Expand Down
13 changes: 13 additions & 0 deletions scripts/setup-integration-test.down.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
#!/usr/bin/env bash

echo "Tearing down integration test environment.."

bash ./core.down.sh

bash ./mock-adapter.down.sh

bash ./postgres.down.sh

bash ./wasmd.down.sh

echo "Teardown finished."
18 changes: 18 additions & 0 deletions scripts/setup-integration-test.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
#!/usr/bin/env bash

echo "Setting up integration test environment.."

core_image=""
if [ -n "${CORE_IMAGE:-}" ]; then
core_image="CORE_IMAGE=${CORE_IMAGE}"
fi

bash ./wasmd.sh

bash ./postgres.sh

bash ./mock-adapter.sh

bash ./core.sh "${core_image}"

echo "Setup finished."
2 changes: 1 addition & 1 deletion scripts/wasmd.sh
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ done
docker run \
"${listen_args[@]}" \
-d \
--platform linux/amd64 \
--platform linux/amd64 \
--name "${container_name}" \
"cosmwasm/wasmd:${container_version}" \
"./setup_and_run.sh" \
Expand Down

0 comments on commit 36ee94b

Please sign in to comment.