From 9bad051a346126f662f24631ac9d86cf8c063a9e Mon Sep 17 00:00:00 2001 From: Michael Street <5597260+MStreet3@users.noreply.github.com> Date: Mon, 23 Dec 2024 17:10:39 -0500 Subject: [PATCH] chore(keystone/changeset): adds unit test --- .../keystone/changeset/deploy_ocr3_test.go | 69 +++++++++++++++++++ 1 file changed, 69 insertions(+) diff --git a/deployment/keystone/changeset/deploy_ocr3_test.go b/deployment/keystone/changeset/deploy_ocr3_test.go index c12f6878835..501e0336a2b 100644 --- a/deployment/keystone/changeset/deploy_ocr3_test.go +++ b/deployment/keystone/changeset/deploy_ocr3_test.go @@ -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" @@ -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 { + 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},