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 56c1438
Showing 1 changed file with 157 additions and 0 deletions.
157 changes: 157 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,162 @@ 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("fails multiple OCR3 contracts but unspecified address", 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)

// 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 original contracts plus one new one
addrs, err := te.Env.ExistingAddresses.AddressesForChain(registrySel)
require.NoError(t, err)
require.Len(t, addrs, 5)

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

Check failure on line 183 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)
}

w := &bytes.Buffer{}
cfg := changeset.ConfigureOCR3Config{
ChainSel: te.RegistrySelector,
NodeIDs: wfNodes,
OCR3Config: &c,
WriteGeneratedConfig: w,
}

_, err = changeset.ConfigureOCR3Contract(te.Env, cfg)
require.Error(t, err)
require.ErrorContains(t, err, "OCR contract address is unspecified")
})

t.Run("fails multiple OCR3 contracts but address not found", 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)

// 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 original contracts plus one new one
addrs, err := te.Env.ExistingAddresses.AddressesForChain(registrySel)
require.NoError(t, err)
require.Len(t, addrs, 5)

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

Check failure on line 226 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)
}

nfa := common.HexToAddress("0x1234567890123456789012345678901234567890")
w := &bytes.Buffer{}
cfg := changeset.ConfigureOCR3Config{
ChainSel: te.RegistrySelector,
NodeIDs: wfNodes,
OCR3Config: &c,
Address: &nfa,
WriteGeneratedConfig: w,
}

_, err = changeset.ConfigureOCR3Contract(te.Env, cfg)
require.Error(t, err)
require.ErrorContains(t, err, "not found in contract set")
})

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

0 comments on commit 56c1438

Please sign in to comment.