Skip to content

Commit

Permalink
Refactored Legacy Gauntlet Commands to GPP Commnads
Browse files Browse the repository at this point in the history
  • Loading branch information
chray-zhang committed Dec 2, 2024
1 parent 007630d commit 14f33cf
Show file tree
Hide file tree
Showing 8 changed files with 211 additions and 44 deletions.
38 changes: 28 additions & 10 deletions integration-tests/common/gauntlet_common.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import (
"errors"
"fmt"
"os"

"github.com/smartcontractkit/chainlink-starknet/integration-tests/utils"
)

Expand All @@ -16,7 +15,8 @@ func (m *OCRv2TestState) fundNodes() ([]string, error) {
if key.TXKey.Data.Attributes.StarkKey == "" {
return nil, errors.New("stark key can't be empty")
}
nAccount, err := m.Clients.GauntletClient.DeployAccountContract(100, key.TXKey.Data.Attributes.StarkKey)
//nAccount, err := m.Clients.GauntletClient.DeployAccountContract(100, key.TXKey.Data.Attributes.StarkKey)
nAccount, err := m.Clients.GauntletPPClient.DeployOzAccount(key.TXKey.Data.Attributes.StarkKey)
if err != nil {
return nil, err
}
Expand All @@ -27,7 +27,8 @@ func (m *OCRv2TestState) fundNodes() ([]string, error) {
for _, key := range nAccounts {
// We are not deploying in parallel here due to testnet limitations (429 too many requests)
l.Debug().Msg(fmt.Sprintf("Funding node with address: %s", key))
_, err := m.Clients.GauntletClient.TransferToken(m.Common.ChainDetails.StarkTokenAddress, key, "10000000000000000000") // Transferring 10 STRK to each node
//_, err := m.Clients.GauntletClient.TransferToken(m.Common.ChainDetails.StarkTokenAddress, key, "10000000000000000000") // Transferring 10 STRK to each node
err := m.Clients.GauntletPPClient.TransferToken(m.Common.ChainDetails.StarkTokenAddress, key, "10000000000000000000")
if err != nil {
return nil, err
}
Expand Down Expand Up @@ -109,26 +110,42 @@ func (m *OCRv2TestState) DeployGauntlet(minSubmissionValue int64, maxSubmissionV
return err
}

err = m.deployLinkToken()
err = m.deployLinkTokenWithGpp()
if err != nil {
return err
}

err = m.deployAccessController()
err = m.deployAccessControllerWithGpp()
if err != nil {
return err
}
// m.Contracts.OCRAddr, err = m.Clients.GauntletClient.DeployOCR2ControllerContract(minSubmissionValue, maxSubmissionValue, decimals, name, m.Contracts.LinkTokenAddr)
// if err != nil {
// return err
// }

m.Contracts.OCRAddr, err = m.Clients.GauntletClient.DeployOCR2ControllerContract(minSubmissionValue, maxSubmissionValue, decimals, name, m.Contracts.LinkTokenAddr)
m.Contracts.OCRAddr, err = m.Clients.GauntletPPClient.DeployOCR2ControllerContract(minSubmissionValue, maxSubmissionValue, decimals, name,
m.Contracts.LinkTokenAddr, m.Account.Account, m.Contracts.AccessControllerAddr)
if err != nil {
return err
}

m.Contracts.ProxyAddr, err = m.Clients.GauntletClient.DeployOCR2ProxyContract(m.Contracts.OCRAddr)
// m.Contracts.ProxyAddr, err = m.Clients.GauntletClient.DeployOCR2ProxyContract(m.Contracts.OCRAddr)
// if err != nil {
// return err
// }

m.Contracts.ProxyAddr, err = m.Clients.GauntletPPClient.DeployOCR2ControllerProxyContract(m.Account.Account, m.Contracts.OCRAddr)
if err != nil {
return err
}
_, err = m.Clients.GauntletClient.AddAccess(m.Contracts.OCRAddr, m.Contracts.ProxyAddr)

// _, err = m.Clients.GauntletClient.AddAccess(m.Contracts.OCRAddr, m.Contracts.ProxyAddr)
// if err != nil {
// return err
// }

err = m.Clients.GauntletPPClient.AddAccess(m.Contracts.OCRAddr, m.Contracts.ProxyAddr)
if err != nil {
return err
}
Expand All @@ -137,7 +154,8 @@ func (m *OCRv2TestState) DeployGauntlet(minSubmissionValue int64, maxSubmissionV
if err != nil {
return err
}
_, err = m.Clients.GauntletClient.SetOCRBilling(observationPaymentGjuels, transmissionPaymentGjuels, m.Contracts.OCRAddr)

_, err = m.Clients.GauntletPPClient.SetOCRBilling(observationPaymentGjuels, transmissionPaymentGjuels, m.Contracts.OCRAddr)
if err != nil {
return err
}
Expand Down
119 changes: 119 additions & 0 deletions integration-tests/common/gauntlet_plus_plus_common.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,70 @@ package common

import (
"encoding/json"
"errors"
"fmt"
"os"
"github.com/smartcontractkit/chainlink-starknet/integration-tests/utils"
)

func (m *OCRv2TestState) fundNodesWithGPP() ([]string, error) {
l := utils.GetTestLogger(m.TestConfig.T)
var nAccounts []string
for _, key := range m.GetNodeKeys() {
if key.TXKey.Data.Attributes.StarkKey == "" {
return nil, errors.New("stark key can't be empty")
}
//nAccount, err := m.Clients.GauntletClient.DeployAccountContract(100, key.TXKey.Data.Attributes.StarkKey)
nAccount, err := m.Clients.GauntletPPClient.DeployOzAccount(key.TXKey.Data.Attributes.StarkKey)
if err != nil {
return nil, err
}
nAccounts = append(nAccounts, nAccount)
}

if *m.Common.TestConfig.Common.Network == "testnet" {
for _, key := range nAccounts {
// We are not deploying in parallel here due to testnet limitations (429 too many requests)
l.Debug().Msg(fmt.Sprintf("Funding node with address: %s", key))
//_, err := m.Clients.GauntletClient.TransferToken(m.Common.ChainDetails.StarkTokenAddress, key, "10000000000000000000") // Transferring 10 STRK to each node
err := m.Clients.GauntletPPClient.TransferToken(m.Common.ChainDetails.StarkTokenAddress, key, "10000000000000000000")
if err != nil {
return nil, err
}
}
} else {
// The starknet provided mint method does not work so we send a req directly
for _, key := range nAccounts {
res, err := m.TestConfig.Resty.R().SetBody(map[string]any{
"address": key,
"amount": 900000000000000000,
}).Post("/mint")
if err != nil {
return nil, err
}
l.Info().Msg(fmt.Sprintf("Funding account (WEI): %s", string(res.Body())))
res, err = m.TestConfig.Resty.R().SetBody(map[string]any{
"address": key,
"amount": 900000000000000000,
"unit": m.Common.ChainDetails.TokenName,
}).Post("/mint")
if err != nil {
return nil, err
}
l.Info().Msg(fmt.Sprintf("Funding account (FRI): %s", string(res.Body())))
}
}

return nAccounts, nil
}

func (m *OCRv2TestState) deployAccessControllerWithGpp() error {
var err error
err = m.Clients.GauntletPPClient.DeclareAccessControllerContract()
if err != nil {
return err
}

m.Contracts.AccessControllerAddr, err = m.Clients.GauntletPPClient.DeployAccessControllerContract(m.Account.Account)
if err != nil {
return err
Expand Down Expand Up @@ -55,3 +114,63 @@ func (m *OCRv2TestState) setConfigDetailsWithGpp(ocrAddress string) error {
_, err = m.Clients.GauntletPPClient.SetConfigDetails(string(parsedConfig), ocrAddress)
return err
}

func (m *OCRv2TestState) DeployGauntletPP(minSubmissionValue int64, maxSubmissionValue int64, decimals int, name string, observationPaymentGjuels int64, transmissionPaymentGjuels int64) error {
err := m.Clients.GauntletClient.InstallDependencies()
if err != nil {
return err
}

m.Clients.ChainlinkClient.AccountAddresses, err = m.fundNodesWithGPP()
if err != nil {
return err
}

err = m.deployLinkTokenWithGpp()
if err != nil {
return err
}

err = m.deployAccessControllerWithGpp()
if err != nil {
return err
}

m.Contracts.OCRAddr, err = m.Clients.GauntletPPClient.DeployOCR2ControllerContract(minSubmissionValue, maxSubmissionValue, decimals, name,
m.Contracts.LinkTokenAddr, m.Account.Account, m.Contracts.AccessControllerAddr)
if err != nil {
return err
}

m.Contracts.ProxyAddr, err = m.Clients.GauntletPPClient.DeployOCR2ControllerProxyContract(m.Account.Account, m.Contracts.OCRAddr)
if err != nil {
return err
}

err = m.Clients.GauntletPPClient.AddAccess(m.Contracts.OCRAddr, m.Contracts.ProxyAddr)
if err != nil {
return err
}

// _, err = m.Clients.GauntletClient.MintLinkToken(m.Contracts.LinkTokenAddr, m.Contracts.OCRAddr, "100000000000000000000")
// if err != nil {
// return err
// }

// Gauntlet PP does not have a mint op. We will use devnet endpoint
_, err = m.TestConfig.Resty.R().SetBody(map[string]any{
"address": m.Contracts.LinkTokenAddr,
"amount": 100000000000000000,
}).Post("/mint")
if err != nil {
return err
}

_, err = m.Clients.GauntletPPClient.SetOCRBilling(observationPaymentGjuels, transmissionPaymentGjuels, m.Contracts.OCRAddr)
if err != nil {
return err
}

err = m.setConfigDetailsWithGpp(m.Contracts.OCRAddr)
return err
}
6 changes: 4 additions & 2 deletions integration-tests/common/test_common.go
Original file line number Diff line number Diff line change
Expand Up @@ -240,14 +240,16 @@ func (m *OCRv2TestState) DeployCluster() {
// Starts GauntletPP Without a network
func (m *OCRv2TestState) StartGppWithoutNetwork() {
gpp := test_env_gauntlet.NewGauntletPlusPlus([]string{}, *m.Common.TestConfig.Common.GauntletPlusPlusImage)
err := gpp.StartContainer()
url, err := gpp.StartContainer()
m.TestConfig.TestConfig.Common.GauntletPlusPlusUrl = url
require.NoError(m.TestConfig.T, err)
}

// Starts GauntletPP with a network
func (m *OCRv2TestState) StartGppWithNetwork(networkName string) {
gpp := test_env_gauntlet.NewGauntletPlusPlus([]string{networkName}, *m.Common.TestConfig.Common.GauntletPlusPlusImage)
err := gpp.StartContainer()
url, err := gpp.StartContainer()
m.TestConfig.TestConfig.Common.GauntletPlusPlusUrl = url
require.NoError(m.TestConfig.T, err)
}

Expand Down
18 changes: 9 additions & 9 deletions integration-tests/docker/testenv/gauntlet/gauntletplusplus.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import (
)

const (
GauntletPlusPlusPort = "7530"
GauntletPlusPlusPort = "4444"
)

type GauntletPlusPlus struct {
Expand Down Expand Up @@ -52,7 +52,7 @@ func (g *GauntletPlusPlus) WithTestLogger(t *testing.T) *GauntletPlusPlus {
return g
}

func (g *GauntletPlusPlus) StartContainer() error {
func (g *GauntletPlusPlus) StartContainer() (string, error) {
l := tc.Logger
if g.t != nil {
l = logging.CustomT{
Expand All @@ -62,7 +62,7 @@ func (g *GauntletPlusPlus) StartContainer() error {
}
cReq, err := g.getContainerRequest()
if err != nil {
return err
return "", err
}
c, err := tc.GenericContainer(testcontext.Get(g.t), tc.GenericContainerRequest{
ContainerRequest: *cReq,
Expand All @@ -71,30 +71,30 @@ func (g *GauntletPlusPlus) StartContainer() error {
Logger: l,
})
if err != nil {
return fmt.Errorf("cannot start GauntletPlusPlus container: %w", err)
return "", fmt.Errorf("cannot start GauntletPlusPlus container: %w", err)
}

g.Container = c
host, err := test_env.GetHost(testcontext.Get(g.t), c)
if err != nil {
return err
return "", err
}

httpPort, err := c.MappedPort(testcontext.Get(g.t), test_env.NatPort(GauntletPlusPlusPort))
if err != nil {
return err
return "", err
}

g.ExternalHTTPURL = fmt.Sprintf("http://%s:%s", host, httpPort.Port())
g.InternalHTTPURL = fmt.Sprintf("http://%s:%s", g.ContainerName, GauntletPlusPlusPort)

g.l.Info().
Any("ExternalHTTPURL", g.ExternalHTTPURL).
Any("ExternalHTTPURL", g.ExternalHTTPURL).
Any("InternalHTTPURL", g.InternalHTTPURL).
Str("containerName", g.ContainerName).
Msgf("Started Starknet container")
Msgf("Started Gauntlet Plus Plus container")

return nil
return g.ExternalHTTPURL, nil
}

func (g *GauntletPlusPlus) getContainerRequest() (*tc.ContainerRequest, error) {
Expand Down
10 changes: 5 additions & 5 deletions integration-tests/smoke/ocr2_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -74,16 +74,16 @@ func TestOCRBasic(t *testing.T) {
}
state.DeployCluster()
// Setting up G++ Client
rpcURL := state.Common.RPCDetails.RPCL2External
gppPort := "http://localhost:" + *state.TestConfig.TestConfig.Common.GauntletPlusPlusPort
state.Clients.GauntletPPClient, err = gauntlet.NewStarknetGauntletPlusPlus(gppPort, rpcURL, state.Account.Account, state.Account.PrivateKey)
require.NoError(t, err, "Setting up gauntlet ++ should not fail")
rpcURL := state.Common.RPCDetails.RPCL2Internal
gppUrl := state.TestConfig.TestConfig.Common.GauntletPlusPlusUrl
state.Clients.GauntletPPClient, err = gauntlet.NewStarknetGauntletPlusPlus(gppUrl, rpcURL, state.Account.Account, state.Account.PrivateKey)
require.NoError(t, err, "Setting up gauntlet++ should not fail")

state.Clients.GauntletClient, err = gauntlet.NewStarknetGauntlet(fmt.Sprintf("%s/", utils.ProjectRoot))
require.NoError(t, err, "Setting up gauntlet should not fail")
err = state.Clients.GauntletClient.SetupNetwork(state.Common.RPCDetails.RPCL2External, state.Account.Account, state.Account.PrivateKey)
require.NoError(t, err, "Setting up gauntlet network should not fail")
err = state.DeployGauntlet(0, 100000000000, decimals, "auto", 1, 1)
err = state.DeployGauntletPP(0, 100000000000, decimals, "auto", 1, 1)
require.NoError(t, err, "Deploying contracts should not fail")

state.SetUpNodes()
Expand Down
8 changes: 7 additions & 1 deletion integration-tests/soak/ocr2_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -78,11 +78,17 @@ func TestOCRBasicSoak(t *testing.T) {
return
}

// Setting up G++ Client
rpcURL := state.Common.RPCDetails.RPCL2Internal
gppUrl := state.TestConfig.TestConfig.Common.GauntletPlusPlusUrl
state.Clients.GauntletPPClient, err = gauntlet.NewStarknetGauntletPlusPlus(gppUrl, rpcURL, state.Account.Account, state.Account.PrivateKey)
require.NoError(t, err, "Setting up gauntlet++ should not fail")

state.Clients.GauntletClient, err = gauntlet.NewStarknetGauntlet(fmt.Sprintf("%s/", utils.ProjectRoot))
require.NoError(t, err, "Setting up gauntlet should not fail")
err = state.Clients.GauntletClient.SetupNetwork(state.Common.RPCDetails.RPCL2External, state.Account.Account, state.Account.PrivateKey)
require.NoError(t, err, "Setting up gauntlet network should not fail")
err = state.DeployGauntlet(0, 100000000000, decimals, "auto", 1, 1)
err = state.DeployGauntletPP(0, 100000000000, decimals, "auto", 1, 1)
require.NoError(t, err, "Deploying contracts should not fail")

state.SetUpNodes()
Expand Down
2 changes: 1 addition & 1 deletion integration-tests/testconfig/testconfig.go
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,7 @@ type Common struct {
DevnetImage *string `toml:"devnet_image"`
GauntletPlusPlusImage *string `toml:"gauntlet_plus_plus_image"`
PostgresVersion *string `toml:"postgres_version"`
GauntletPlusPlusPort *string `toml:"gauntlet_plus_plus_port"`
GauntletPlusPlusUrl string
}

func (c *Common) Validate() error {
Expand Down
Loading

0 comments on commit 14f33cf

Please sign in to comment.