Skip to content

Commit

Permalink
integration-tests/ocr2_test.go: fund nodes
Browse files Browse the repository at this point in the history
  • Loading branch information
calvwang9 committed Aug 10, 2023
1 parent 8eaec3e commit 6f012fa
Showing 1 changed file with 35 additions and 1 deletion.
36 changes: 35 additions & 1 deletion integration-tests/ocr2_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,15 @@ import (
"github.com/smartcontractkit/chainlink-cosmos/pkg/cosmos/adapters/cosmwasm"
"github.com/smartcontractkit/chainlink-cosmos/pkg/cosmos/client"
"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"
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"
)
Expand Down Expand Up @@ -60,7 +64,37 @@ func TestOCRBasic(t *testing.T) {
err = cg.SetupNetwork(commonConfig.NodeUrl, commonConfig.Mnemonic)
require.NoError(t, err, "Setting up gauntlet network should not fail")

// TODO: fund nodes if necessary
// Fund nodes with native tokens for gas
gpe := client.NewFixedGasPriceEstimator(map[string]types.DecCoin{
"ucosm": types.NewDecCoinFromDec("ucosm", types.MustNewDecFromStr("0.01")),
})
gasPrices, err := gpe.GasPrices()
require.NoError(t, err, "Could not get gas prices")
from := types.MustAccAddressFromBech32(commonConfig.Account)
amount := []types.Coin{types.NewCoin("ucosm", types.NewInt(int64(10000000)))}
accountNumber, sequenceNumber, err := cosmosClient.Account(from)
require.NoError(t, err, "Could not get account")
privateKey, _, err := testutil.CreateKeyFromMnemonic(commonConfig.Mnemonic)
require.NoError(t, err, "Could not create private key from mnemonic")

for i, nodeAddr := range chainlinkClient.GetNodeAddresses() {
to := types.MustAccAddressFromBech32(nodeAddr)
msgSend := banktypes.NewMsgSend(from, to, amount)
resp, err := cosmosClient.SignAndBroadcast([]types.Msg{msgSend}, accountNumber, sequenceNumber+uint64(i), gasPrices["ucosm"], 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", commonConfig.Account).
Str("to", nodeAddr).
Str("amount", "10000000").
Str("token", "ucosm").
Msg("Sucessfully sent native tokens")
balance, err := cosmosClient.Balance(to, "ucosm")
require.NoError(t, err, "Could not fetch ucosm balance")
require.Equal(t, balance.String(), "10000000ucosm")
}

// Upload contracts
_, err = cg.UploadContracts(nil)
Expand Down

0 comments on commit 6f012fa

Please sign in to comment.