Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/develop' into BCF-2612-ChainReader
Browse files Browse the repository at this point in the history
# Conflicts:
#	integration-tests/go.sum
  • Loading branch information
ilija42 committed Nov 17, 2023
2 parents 89dcfdd + c7eb330 commit 1479d54
Show file tree
Hide file tree
Showing 10 changed files with 334 additions and 108 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,104 @@
import { Result } from '@chainlink/gauntlet-core'
import { logger, prompt } from '@chainlink/gauntlet-core/dist/utils'
import { SolanaCommand, TransactionResponse } from '@chainlink/gauntlet-solana'
import { PublicKey } from '@solana/web3.js'
import { CONTRACT_LIST, getContract } from '../../../lib/contracts'

type Input = {
transmitter: string
}

type ContractInput = {
transmitter: string
proposedPayee: PublicKey
}

export default class AcceptPayeeship extends SolanaCommand {
static id = 'ocr2:accept_payeeship'
static category = CONTRACT_LIST.OCR_2
static examples = ['yarn gauntlet ocr2:accept_payeeship --network=<NETWORK> --transmitter=<TRANSMITTER> <CONTRACT>']

input: Input
contractInput: ContractInput

makeInput = (userInput: any): Input => {
if (userInput) return userInput as Input

if (!this.flags.transmitter) {
throw Error('Please specify a valid transmitter (--transmitter))')
}

return {
transmitter: this.flags.transmitter,
}
}

makeContractInput = async (input: Input): Promise<ContractInput> => {
const state = new PublicKey(this.args[0])
const contractState = (await this.program.account.state.fetch(state)) as any
const contractOracles = contractState.oracles?.xs.slice(0, contractState.oracles.len.toNumber())
const oracle = contractOracles.find(({ transmitter }) => transmitter.toString() == input.transmitter)

if (!oracle) {
throw Error(`No oracle found with the transmitter id ${input.transmitter}`)
}

return {
transmitter: input.transmitter,
proposedPayee: oracle.proposedPayee,
}
}

constructor(flags, args) {
super(flags, args)
}

buildCommand = async (flags, args) => {
const ocr2 = getContract(CONTRACT_LIST.OCR_2, '')
this.program = this.loadProgram(ocr2.idl, ocr2.programId.toString())
this.input = this.makeInput(flags.input)
this.contractInput = await this.makeContractInput(this.input)

return this
}

makeRawTransaction = async (signer: PublicKey) => {
const data = this.program.instruction.acceptPayeeship({
accounts: {
state: new PublicKey(this.args[0]),
authority: signer,
transmitter: this.contractInput.transmitter,
proposedPayee: this.contractInput.proposedPayee,
},
})

return [data]
}

beforeExecute = async () => {
logger.loading(`Accepting payeeship for transmitter ${this.contractInput.transmitter}...`)
await prompt(`Continue?`)
}

execute = async () => {
await this.buildCommand(this.flags, this.args)

const signer = this.wallet.publicKey

const rawTx = await this.makeRawTransaction(signer)
await this.simulateTx(signer, rawTx)
await this.beforeExecute()

const txhash = await this.signAndSendRawTx(rawTx)
logger.success(`Payeeship accepted on tx hash: ${txhash}`)

return {
responses: [
{
tx: this.wrapResponse(txhash, this.args[0]),
contract: this.args[0],
},
],
} as Result<TransactionResponse>
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ import CreateProposal from './proposal/createProposal'
import ProposeConfig from './proposeConfig'
import ProposeOffchainConfig from './proposeOffchainConfig'
import ProposePayees from './proposePayees'
import TransferPayeeship from './transferPayeeship'
import AcceptPayeeship from './acceptPayeeship'
import FinalizeProposal from './proposal/finalizeProposal'
import Close from './close'
import WithdrawFunds from './withdrawFunds'
Expand All @@ -41,6 +43,8 @@ export default [
ProposeConfig,
ProposeOffchainConfig,
ProposePayees,
TransferPayeeship,
AcceptPayeeship,
ReadState,
SetBillingAccessController,
SetRequesterAccessController,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,117 @@
import { Result } from '@chainlink/gauntlet-core'
import { logger, prompt } from '@chainlink/gauntlet-core/dist/utils'
import { SolanaCommand, TransactionResponse } from '@chainlink/gauntlet-solana'
import { PublicKey } from '@solana/web3.js'
import { CONTRACT_LIST, getContract } from '../../../lib/contracts'

type Input = {
transmitter: string
proposedPayee: string
}

type ContractInput = {
transmitter: string
payee: PublicKey
proposedPayee: PublicKey
}

export default class TransferPayeeship extends SolanaCommand {
static id = 'ocr2:transfer_payeeship'
static category = CONTRACT_LIST.OCR_2
static examples = [
'yarn gauntlet ocr2:transfer_payeeship --network=<NETWORK> --transmitter=<TRANSMITTER> --proposedPayee=<PROPOSED_PAYEE> <CONTRACT>',
]

input: Input
contractInput: ContractInput

makeInput = (userInput: any): Input => {
if (userInput) return userInput as Input

if (!this.flags.transmitter) {
throw Error('Please specify a valid transmitter (--transmitter))')
}

if (!this.flags.proposedPayee) {
throw Error('Please specify a valid proposed payee (--proposedPayee)')
}

return {
transmitter: this.flags.transmitter,
proposedPayee: this.flags.proposedPayee,
}
}

makeContractInput = async (input: Input): Promise<ContractInput> => {
const state = new PublicKey(this.args[0])
const contractState = (await this.program.account.state.fetch(state)) as any
const contractOracles = contractState.oracles?.xs.slice(0, contractState.oracles.len.toNumber())
const oracle = contractOracles.find(({ transmitter }) => transmitter.toString() == input.transmitter)

if (!oracle) {
throw Error(`No oracle found with the transmitter id ${input.transmitter}`)
}

return {
transmitter: input.transmitter,
payee: new PublicKey(oracle.payee),
proposedPayee: new PublicKey(input.proposedPayee),
}
}

constructor(flags, args) {
super(flags, args)
}

buildCommand = async (flags, args) => {
const ocr2 = getContract(CONTRACT_LIST.OCR_2, '')
this.program = this.loadProgram(ocr2.idl, ocr2.programId.toString())
this.input = this.makeInput(flags.input)
this.contractInput = await this.makeContractInput(this.input)

return this
}

makeRawTransaction = async (signer: PublicKey) => {
const data = this.program.instruction.transferPayeeship({
accounts: {
state: new PublicKey(this.args[0]),
authority: signer,
transmitter: this.contractInput.transmitter,
payee: this.contractInput.payee,
proposedPayee: this.contractInput.proposedPayee,
},
})

return [data]
}

beforeExecute = async () => {
logger.loading(
`Transferring payeeship for transmitter ${this.contractInput.transmitter}: ${this.contractInput.payee} -> ${this.contractInput.proposedPayee}`,
)
await prompt(`Continue?`)
}

execute = async () => {
await this.buildCommand(this.flags, this.args)

const signer = this.wallet.publicKey

const rawTx = await this.makeRawTransaction(signer)
await this.simulateTx(signer, rawTx)
await this.beforeExecute()

const txhash = await this.signAndSendRawTx(rawTx)
logger.success(`Payeeship transferred on tx hash: ${txhash}`)

return {
responses: [
{
tx: this.wrapResponse(txhash, this.args[0]),
contract: this.args[0],
},
],
} as Result<TransactionResponse>
}
}
22 changes: 11 additions & 11 deletions integration-tests/common/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,22 +18,22 @@ import (
"golang.org/x/crypto/curve25519"
"gopkg.in/guregu/null.v4"

"github.com/smartcontractkit/chainlink-env/environment"
"github.com/smartcontractkit/chainlink-env/pkg/alias"
"github.com/smartcontractkit/chainlink-env/pkg/helm/chainlink"
mock_adapter "github.com/smartcontractkit/chainlink-env/pkg/helm/mock-adapter"
"github.com/smartcontractkit/chainlink-env/pkg/helm/sol"
"github.com/smartcontractkit/chainlink-solana/pkg/solana"
"github.com/smartcontractkit/chainlink-testing-framework/k8s/environment"
"github.com/smartcontractkit/chainlink-testing-framework/k8s/pkg/alias"
"github.com/smartcontractkit/chainlink-testing-framework/k8s/pkg/helm/chainlink"
mock_adapter "github.com/smartcontractkit/chainlink-testing-framework/k8s/pkg/helm/mock-adapter"
"github.com/smartcontractkit/chainlink-testing-framework/k8s/pkg/helm/sol"

"github.com/smartcontractkit/libocr/offchainreporting2/confighelper"
"github.com/smartcontractkit/libocr/offchainreporting2/reportingplugin/median"
"github.com/smartcontractkit/libocr/offchainreporting2/types"

"github.com/smartcontractkit/chainlink-testing-framework/utils/ptr"
"github.com/smartcontractkit/chainlink/integration-tests/client"
"github.com/smartcontractkit/chainlink/integration-tests/contracts"
"github.com/smartcontractkit/chainlink/integration-tests/docker/test_env"
"github.com/smartcontractkit/chainlink/integration-tests/types/config/node"
"github.com/smartcontractkit/chainlink/integration-tests/utils"
"github.com/smartcontractkit/chainlink/v2/core/services/job"
"github.com/smartcontractkit/chainlink/v2/core/store/models"

Expand Down Expand Up @@ -496,11 +496,11 @@ func BuildNodeContractPairID(node *client.ChainlinkClient, ocr2Addr string) (str

func (c *Common) DefaultNodeConfig() *cl.Config {
solConfig := solana.TOMLConfig{
Enabled: utils.Ptr(true),
ChainID: utils.Ptr(c.ChainId),
Enabled: ptr.Ptr(true),
ChainID: ptr.Ptr(c.ChainId),
Nodes: []*solcfg.Node{
{
Name: utils.Ptr("primary"),
Name: ptr.Ptr("primary"),
URL: relay_utils.MustParseURL(c.SolanaUrl),
},
},
Expand All @@ -509,8 +509,8 @@ func (c *Common) DefaultNodeConfig() *cl.Config {
baseConfig.Solana = solana.TOMLConfigs{
&solConfig,
}
baseConfig.OCR2.Enabled = utils.Ptr(true)
baseConfig.P2P.V2.Enabled = utils.Ptr(true)
baseConfig.OCR2.Enabled = ptr.Ptr(true)
baseConfig.P2P.V2.Enabled = ptr.Ptr(true)
fiveSecondDuration := models.MustMakeDuration(5 * time.Second)
baseConfig.P2P.V2.DeltaDial = &fiveSecondDuration
baseConfig.P2P.V2.DeltaReconcile = &fiveSecondDuration
Expand Down
4 changes: 2 additions & 2 deletions integration-tests/common/test_common.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import (
test_env_sol "github.com/smartcontractkit/chainlink-solana/integration-tests/docker/test_env"
"github.com/smartcontractkit/chainlink-solana/integration-tests/solclient"
"github.com/smartcontractkit/chainlink-testing-framework/logging"
"github.com/smartcontractkit/chainlink-testing-framework/utils"
"github.com/smartcontractkit/chainlink-testing-framework/utils/osutil"

"golang.org/x/sync/errgroup"

Expand Down Expand Up @@ -630,7 +630,7 @@ func (m *OCRv2TestState) ConfigureGauntlet(secret string) map[string]string {

// GauntletEnvToRemoteRunner Setup the environment variables that will be needed inside the remote runner
func (m *OCRv2TestState) GauntletEnvToRemoteRunner() {
utils.SetupEnvVarsForRemoteRunner([]string{
osutil.SetupEnvVarsForRemoteRunner([]string{
"RPC_URL",
"WS_URL",
"PRIVATE_KEY",
Expand Down
9 changes: 5 additions & 4 deletions integration-tests/docker/test_env/sol.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import (
"github.com/smartcontractkit/chainlink-solana/integration-tests/utils"
"github.com/smartcontractkit/chainlink-testing-framework/docker/test_env"
"github.com/smartcontractkit/chainlink-testing-framework/logging"
"github.com/smartcontractkit/chainlink-testing-framework/utils/testcontext"
)

const (
Expand Down Expand Up @@ -78,7 +79,7 @@ func (s *Solana) StartContainer() error {
if err != nil {
return err
}
c, err := tc.GenericContainer(context.Background(), tc.GenericContainerRequest{
c, err := tc.GenericContainer(testcontext.Get(s.t), tc.GenericContainerRequest{
ContainerRequest: *cReq,
Reuse: true,
Started: true,
Expand All @@ -88,15 +89,15 @@ func (s *Solana) StartContainer() error {
return fmt.Errorf("cannot start Solana container: %w", err)
}
s.Container = c
host, err := test_env.GetHost(context.Background(), c)
host, err := test_env.GetHost(testcontext.Get(s.t), c)
if err != nil {
return err
}
httpPort, err := c.MappedPort(context.Background(), test_env.NatPort(SOL_HTTP_PORT))
httpPort, err := c.MappedPort(testcontext.Get(s.t), test_env.NatPort(SOL_HTTP_PORT))
if err != nil {
return err
}
wsPort, err := c.MappedPort(context.Background(), test_env.NatPort(SOL_WS_PORT))
wsPort, err := c.MappedPort(testcontext.Get(s.t), test_env.NatPort(SOL_WS_PORT))
if err != nil {
return err
}
Expand Down
Loading

0 comments on commit 1479d54

Please sign in to comment.