Skip to content

Commit

Permalink
test: add gauntlet logic + convert wallets to addresses only
Browse files Browse the repository at this point in the history
  • Loading branch information
aalu1418 committed Mar 29, 2024
1 parent 837bfdb commit 04d40a4
Show file tree
Hide file tree
Showing 8 changed files with 112 additions and 55 deletions.
91 changes: 71 additions & 20 deletions integration-tests/common/test_common.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,13 @@ import (
"fmt"
"math/big"
"os"
"sort"
"strings"
"sync"
"testing"
"time"

"github.com/gagliardetto/solana-go"
"github.com/onsi/gomega"
"github.com/rs/zerolog"
"github.com/rs/zerolog/log"
Expand Down Expand Up @@ -126,7 +128,7 @@ func (m *OCRv2TestState) LabelChaosGroups() {
m.LabelChaosGroup(10, 19, ChaosGroupRightHalf)
}

func (m *OCRv2TestState) DeployCluster(contractsDir string) {
func (m *OCRv2TestState) DeployCluster(contractsDir string, enableGauntlet bool) {
if m.Common.IsK8s {
m.DeployEnv(contractsDir)
} else {
Expand Down Expand Up @@ -155,7 +157,7 @@ func (m *OCRv2TestState) DeployCluster(contractsDir string) {
Killgrave: env.MockAdapter,
}
}
m.SetupClients()
m.SetupClients(enableGauntlet)
m.DeployContracts(contractsDir)
m.CreateJobs()
}
Expand Down Expand Up @@ -206,7 +208,7 @@ func (m *OCRv2TestState) NewSolanaClientSetup(networkSettings *solclient.SolNetw
}

func (m *OCRv2TestState) NewGauntletSetup() (*gauntlet.SolanaGauntlet, error) {
cfg := m.ConfigureGauntlet("this is an testing only secret") // TODO: move secret
cfg := m.ConfigureGauntlet(utils.TestingSecret)
g, err := gauntlet.NewSolanaGauntlet(fmt.Sprintf("%s/gauntlet", utils.ProjectRoot))
if err != nil {
return nil, err
Expand Down Expand Up @@ -304,27 +306,76 @@ func (m *OCRv2TestState) DeployFeedWithGauntlet(i int) error {
_, err := m.Gauntlet.DeployOCR2()
require.NoError(m.T, err, "Error deploying OCR")

var nodeCount int
if m.Common.IsK8s {
nodeCount = len(m.ContractsNodeSetup[i].NodesK8s)
} else {
nodeCount = len(m.ContractsNodeSetup[i].Nodes)
}
ocConfig, err := OffChainConfigParamsFromNodes(nodeCount, m.ContractsNodeSetup[i].NodeKeysBundle)
gauntletConfig := m.ConfigureGauntlet(utils.TestingSecret)
bundleData := make([]client.NodeKeysBundle, len(m.ContractsNodeSetup[i].NodeKeysBundle))
copy(bundleData, m.ContractsNodeSetup[i].NodeKeysBundle)

// We have to sort by on_chain_pub_key for the config digest
sort.Slice(bundleData, func(i, j int) bool {
return bundleData[i].OCR2Key.Data.Attributes.OnChainPublicKey < bundleData[j].OCR2Key.Data.Attributes.OnChainPublicKey
})

onChainConfig, err := m.GenerateOnChainConfig(bundleData, gauntletConfig["VAULT"], m.Gauntlet.ProposalAddress)
require.NoError(m.T, err)

// TODO: use gauntlet
reportingConfig := utils.ReportingPluginConfig{
AlphaReportInfinite: false,
AlphaReportPpb: 0,
AlphaAcceptInfinite: false,
AlphaAcceptPpb: 0,
DeltaCNanoseconds: 0,
}
offChainConfig := m.GenerateOffChainConfig(
bundleData,
m.Gauntlet.ProposalAddress,
reportingConfig,
int64(20000000000),
int64(50000000000),
int64(1000000000),
int64(4000000000),
int64(50000000000),
3,
int64(0),
int64(3000000000),
int64(3000000000),
int64(100000000),
int64(100000000),
utils.TestingSecret,
)

payees := m.GeneratePayees(bundleData, gauntletConfig["VAULT"], m.Gauntlet.ProposalAddress)
proposalAccept := m.GenerateProposalAcceptConfig(m.Gauntlet.ProposalAddress, 2, 1, onChainConfig.Oracles, offChainConfig.OffchainConfig, utils.TestingSecret)

err = m.Gauntlet.ConfigureOCR2(onChainConfig, offChainConfig, payees, proposalAccept)
require.NoError(m.T, err)

// TODO: standardize config generation
// var nodeCount int
// if m.Common.IsK8s {
// nodeCount = len(m.ContractsNodeSetup[i].NodesK8s)
// } else {
// nodeCount = len(m.ContractsNodeSetup[i].Nodes)
// }
// ocConfig, err := OffChainConfigParamsFromNodes(nodeCount, m.ContractsNodeSetup[i].NodeKeysBundle)
// require.NoError(m.T, err)
// err = ocr2.Configure(ocConfig)
// require.NoError(m.T, err)
// m.Mu.Lock()
// m.Contracts = append(m.Contracts, Contracts{
// BAC: bac,
// RAC: rac,
// OCR2: ocr2,
// Store: store,
// StoreAuth: storeAuth,
// })
// m.Mu.Unlock()

m.Mu.Lock()
m.Contracts = append(m.Contracts, Contracts{
OCR2: &solclient.OCRv2{
Client: m.Client,
State: solana.MustPublicKeyFromBase58(m.Gauntlet.OcrAddress),
ProgramWallet: m.Client.ProgramWallets["ocr2-keypair.json"].PublicKey(),
},
Store: &solclient.Store{
Client: m.Client,
Store: solana.MustPublicKeyFromBase58(m.Gauntlet.StoreAddress),
Feed: solana.MustPublicKeyFromBase58(m.Gauntlet.FeedAddress),
ProgramWallet: m.Client.ProgramWallets["store-keypair.json"].PublicKey(),
},
})
m.Mu.Unlock()
return nil
}

Expand Down
2 changes: 1 addition & 1 deletion integration-tests/gauntlet/gauntlet_solana.go
Original file line number Diff line number Diff line change
Expand Up @@ -481,7 +481,7 @@ func (sg *SolanaGauntlet) ConfigureOCR2(onChainConfig utils.OCR2OnChainConfig, o
if err != nil {
return err
}
_, err = sg.AcceptProposal(sg.ProposalAddress, "this is an testing only secret", proposalAccept, sg.OcrAddress)
_, err = sg.AcceptProposal(sg.ProposalAddress, utils.TestingSecret, proposalAccept, sg.OcrAddress)
if err != nil {
return err
}
Expand Down
17 changes: 9 additions & 8 deletions integration-tests/smoke/ocr2_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,14 +34,16 @@ import (

func TestSolanaOCRV2Smoke(t *testing.T) {
for _, test := range []struct {
name string
env map[string]string
name string
env map[string]string
enableGauntlet bool
}{
{name: "embedded"},
{name: "plugins", env: map[string]string{
"CL_MEDIAN_CMD": "chainlink-feeds",
"CL_SOLANA_CMD": "chainlink-solana",
}},
{name: "embedded-gauntlet", enableGauntlet: true},
} {
config, err := tc.GetConfig("Smoke", tc.OCR2)
if err != nil {
Expand All @@ -62,7 +64,7 @@ func TestSolanaOCRV2Smoke(t *testing.T) {
maps.Copy(n.ContainerEnvs, test.env)
})
}
state.DeployCluster(utils.ContractsDir)
state.DeployCluster(utils.ContractsDir, test.enableGauntlet)

state.ValidateRoundsAfter(time.Now(), common.NewRoundCheckTimeout, 1)
})
Expand All @@ -75,7 +77,6 @@ func TestSolanaGauntletOCRV2Smoke(t *testing.T) {
t.Fatal(err)
}
l := logging.GetTestLogger(t)
secret := "this is an testing only secret"
state, err := common.NewOCRv2State(t, 1, "gauntlet", "devnet", true, &config)
require.NoError(t, err, "Could not setup the ocrv2 state")
if state.Common.Env.WillUseRemoteRunner() {
Expand All @@ -94,13 +95,13 @@ func TestSolanaGauntletOCRV2Smoke(t *testing.T) {
l.Error().Err(err).Msg("Error tearing down environment")
}
})
state.SetupClients()
state.SetupClients(false) // not setting up gauntlet because it is set up outside
state.NodeKeysBundle, err = state.Common.CreateNodeKeysBundle(state.GetChainlinkNodes())
require.NoError(t, err)
err = state.Common.CreateSolanaChainAndNode(state.GetChainlinkNodes())
require.NoError(t, err)

gauntletConfig := state.ConfigureGauntlet(secret)
gauntletConfig := state.ConfigureGauntlet(utils.TestingSecret)
err = sg.SetupNetwork(gauntletConfig)
require.NoError(t, err, "Error setting gauntlet network")

Expand Down Expand Up @@ -145,11 +146,11 @@ func TestSolanaGauntletOCRV2Smoke(t *testing.T) {
int64(3000000000),
int64(100000000),
int64(100000000),
secret,
utils.TestingSecret,
)

payees := state.GeneratePayees(bundleData, gauntletConfig["VAULT"], sg.ProposalAddress)
proposalAccept := state.GenerateProposalAcceptConfig(sg.ProposalAddress, 2, 1, onChainConfig.Oracles, offChainConfig.OffchainConfig, secret)
proposalAccept := state.GenerateProposalAcceptConfig(sg.ProposalAddress, 2, 1, onChainConfig.Oracles, offChainConfig.OffchainConfig, utils.TestingSecret)

require.NoError(t, err)
err = sg.ConfigureOCR2(onChainConfig, offChainConfig, payees, proposalAccept)
Expand Down
2 changes: 1 addition & 1 deletion integration-tests/soak/ocr2_soak_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,6 @@ func TestSolanaOCRV2SoakTest(t *testing.T) {
require.NoError(t, err)
return
}
state.DeployCluster(utils.ContractsDir)
state.DeployCluster(utils.ContractsDir, false)
state.ValidateRoundsAfter(time.Now(), common.NewSoakRoundsCheckTimeout, 20000)
}
10 changes: 5 additions & 5 deletions integration-tests/solclient/deployer.go
Original file line number Diff line number Diff line change
Expand Up @@ -186,10 +186,10 @@ func (c *ContractDeployer) DeployOCRv2Store(billingAC string) (*Store, error) {
}
return &Store{
Client: c.Client,
Store: c.Accounts.Store,
Feed: c.Accounts.Feed,
Store: c.Accounts.Store.PublicKey(),
Feed: c.Accounts.Feed.PublicKey(),
Owner: c.Accounts.Owner,
ProgramWallet: programWallet,
ProgramWallet: programWallet.PublicKey(),
}, nil
}

Expand Down Expand Up @@ -347,13 +347,13 @@ func (c *ContractDeployer) InitOCR2(billingControllerAddr string, requesterContr
return &OCRv2{
ContractDeployer: c,
Client: c.Client,
State: c.Accounts.OCR,
State: c.Accounts.OCR.PublicKey(),
Authorities: c.Accounts.Authorities,
Owner: c.Accounts.Owner,
Proposal: c.Accounts.Proposal,
OCRVaultAssociatedPubKey: *assocVault,
Mint: c.Accounts.Mint,
ProgramWallet: programWallet,
ProgramWallet: programWallet.PublicKey(),
}, nil
}

Expand Down
16 changes: 8 additions & 8 deletions integration-tests/solclient/ocr2.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,18 +20,18 @@ import (
type OCRv2 struct {
Client *Client
ContractDeployer *ContractDeployer
State *solana.Wallet
State solana.PublicKey
Authorities map[string]*Authority
Payees []*solana.Wallet
Owner *solana.Wallet
Proposal *solana.Wallet
Mint *solana.Wallet
OCRVaultAssociatedPubKey solana.PublicKey
ProgramWallet *solana.Wallet
ProgramWallet solana.PublicKey
}

func (m *OCRv2) ProgramAddress() string {
return m.ProgramWallet.PublicKey().String()
return m.ProgramWallet.String()
}

func (m *OCRv2) writeOffChainConfig(ocConfigBytes []byte) error {
Expand Down Expand Up @@ -71,7 +71,7 @@ func (m *OCRv2) acceptProposal(digest []byte) error {
[]solana.Instruction{
ocr_2.NewAcceptProposalInstruction(
digest,
m.State.PublicKey(),
m.State,
m.Proposal.PublicKey(),
m.Owner.PublicKey(),
m.OCRVaultAssociatedPubKey,
Expand Down Expand Up @@ -112,7 +112,7 @@ func (m *OCRv2) SetBilling(observationPayment uint32, transmissionPayment uint32
ocr_2.NewSetBillingInstruction(
observationPayment,
transmissionPayment,
m.State.PublicKey(),
m.State,
m.Owner.PublicKey(),
m.Owner.PublicKey(),
billingACPubKey,
Expand Down Expand Up @@ -302,7 +302,7 @@ func (m *OCRv2) DumpState() error {
var stateDump ocr_2.State
err := m.Client.RPC.GetAccountDataInto(
context.Background(),
m.State.PublicKey(),
m.State,
&stateDump,
)
if err != nil {
Expand All @@ -318,7 +318,7 @@ func (m *OCRv2) GetContractData(ctx context.Context) (*contracts.OffchainAggrega

// ProposeConfig sets oracles with payee addresses
func (m *OCRv2) proposeConfig(ocConfig contracts.OffChainAggregatorV2Config) error {
log.Info().Str("Program Address", m.ProgramWallet.PublicKey().String()).Msg("Proposing new config")
log.Info().Str("Program Address", m.ProgramWallet.String()).Msg("Proposing new config")
payer := m.Client.DefaultWallet
oracles := make([]ocr_2.NewOracle, 0)
for _, oc := range ocConfig.Oracles {
Expand Down Expand Up @@ -407,7 +407,7 @@ func (m *OCRv2) RequestNewRound() error {
}

func (m *OCRv2) Address() string {
return m.State.PublicKey().String()
return m.State.String()
}

func (m *OCRv2) TransferOwnership(to string) error {
Expand Down
25 changes: 13 additions & 12 deletions integration-tests/solclient/store.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,22 +11,22 @@ import (

type Store struct {
Client *Client
Store *solana.Wallet
Feed *solana.Wallet
Store solana.PublicKey
Feed solana.PublicKey
Owner *solana.Wallet
ProgramWallet *solana.Wallet
ProgramWallet solana.PublicKey
}

func (m *Store) GetLatestRoundData() (uint64, uint64, uint64, error) {
a, _, err := relaySol.GetLatestTransmission(context.Background(), m.Client.RPC, m.Feed.PublicKey(), rpc.CommitmentConfirmed)
a, _, err := relaySol.GetLatestTransmission(context.Background(), m.Client.RPC, m.Feed, rpc.CommitmentConfirmed)
if err != nil {
return 0, 0, 0, err
}
return a.Data.Uint64(), uint64(a.Timestamp), 0, nil
}

func (m *Store) TransmissionsAddress() string {
return m.Feed.PublicKey().String()
return m.Feed.String()
}

func (m *Store) SetValidatorConfig(flaggingThreshold uint32) error {
Expand All @@ -36,7 +36,7 @@ func (m *Store) SetValidatorConfig(flaggingThreshold uint32) error {
[]solana.Instruction{
store.NewSetValidatorConfigInstruction(
flaggingThreshold,
m.Feed.PublicKey(),
m.Feed,
m.Owner.PublicKey(),
m.Owner.PublicKey(),
).Build(),
Expand Down Expand Up @@ -69,7 +69,7 @@ func (m *Store) SetWriter(writerAuthority string) error {
[]solana.Instruction{
store.NewSetWriterInstruction(
writerAuthPubKey,
m.Feed.PublicKey(),
m.Feed,
m.Owner.PublicKey(),
m.Owner.PublicKey(),
).Build(),
Expand All @@ -78,9 +78,10 @@ func (m *Store) SetWriter(writerAuthority string) error {
if key.Equals(m.Owner.PublicKey()) {
return &m.Owner.PrivateKey
}
if key.Equals(m.Feed.PublicKey()) {
return &m.Feed.PrivateKey
}
// TODO: is this needed?
// if key.Equals(m.Feed)) {
// return &m.Feed.PrivateKey
// }
if key.Equals(payer.PublicKey()) {
return &payer.PrivateKey
}
Expand All @@ -95,9 +96,9 @@ func (m *Store) SetWriter(writerAuthority string) error {
}

func (m *Store) ProgramAddress() string {
return m.ProgramWallet.PublicKey().String()
return m.ProgramWallet.String()
}

func (m *Store) Address() string {
return m.Store.PublicKey().String()
return m.Store.String()
}
4 changes: 4 additions & 0 deletions integration-tests/utils/offchainConfig.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
package utils

const (
TestingSecret = "this is an testing only secret"
)

type OCR2OnChainConfig struct {
Oracles []Operator `json:"oracles"`
F int `json:"f"`
Expand Down

0 comments on commit 04d40a4

Please sign in to comment.