Skip to content

Commit

Permalink
chore(keystone/changeset): adds unit test
Browse files Browse the repository at this point in the history
  • Loading branch information
MStreet3 committed Dec 23, 2024
1 parent 969a96a commit 9bad051
Showing 1 changed file with 69 additions and 0 deletions.
69 changes: 69 additions & 0 deletions deployment/keystone/changeset/deploy_ocr3_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (

"go.uber.org/zap/zapcore"

"github.com/ethereum/go-ethereum/common"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"

Expand Down Expand Up @@ -85,6 +86,74 @@ func TestConfigureOCR3(t *testing.T) {
assert.Nil(t, csOut.Proposals)
})

t.Run("success multiple OCR3 contracts", func(t *testing.T) {
te := test.SetupTestEnv(t, test.TestConfig{
WFDonConfig: test.DonConfig{N: 4},
AssetDonConfig: test.DonConfig{N: 4},
WriterDonConfig: test.DonConfig{N: 4},
NumChains: 1,
})

registrySel := te.Env.AllChainSelectors()[0]

existingContracts, err := te.Env.ExistingAddresses.AddressesForChain(registrySel)
require.NoError(t, err)
require.Len(t, existingContracts, 4)

// Find existing OCR3 contract
var existingOCR3Addr string
for addr, tv := range existingContracts {
if tv.Type == internal.OCR3Capability {
existingOCR3Addr = addr
break
}
}

// Deploy a new OCR3 contract
resp, err := changeset.DeployOCR3(te.Env, registrySel)
require.NoError(t, err)
require.NotNil(t, resp)
require.NoError(t, te.Env.ExistingAddresses.Merge(resp.AddressBook))

// Verify after merge there are three original contracts plus one new one
addrs, err := te.Env.ExistingAddresses.AddressesForChain(registrySel)
require.NoError(t, err)
require.Len(t, addrs, 5)

// Find new OCR3 contract
var newOCR3Addr string
for addr, tv := range addrs {
if tv.Type == internal.OCR3Capability && addr != existingOCR3Addr {
newOCR3Addr = addr
break
}
}

var wfNodes []string
for id, _ := range te.WFNodes {

Check failure on line 133 in deployment/keystone/changeset/deploy_ocr3_test.go

View workflow job for this annotation

GitHub Actions / GolangCI Lint (deployment)

range: should omit 2nd value from range; this loop is equivalent to `for id := range ...` (revive)
wfNodes = append(wfNodes, id)
}

na := common.HexToAddress(newOCR3Addr)
w := &bytes.Buffer{}
cfg := changeset.ConfigureOCR3Config{
ChainSel: te.RegistrySelector,
NodeIDs: wfNodes,
Address: &na, // Use the new OCR3 contract to configure
OCR3Config: &c,
WriteGeneratedConfig: w,
}

csOut, err := changeset.ConfigureOCR3Contract(te.Env, cfg)
require.NoError(t, err)
var got internal.OCR2OracleConfig
err = json.Unmarshal(w.Bytes(), &got)
require.NoError(t, err)
assert.Len(t, got.Signers, 4)
assert.Len(t, got.Transmitters, 4)
assert.Nil(t, csOut.Proposals)
})

t.Run("mcms", func(t *testing.T) {
te := test.SetupTestEnv(t, test.TestConfig{
WFDonConfig: test.DonConfig{N: 4},
Expand Down

0 comments on commit 9bad051

Please sign in to comment.