-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
239 additions
and
38 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
package commitrmnocb |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,211 @@ | ||
package commitrmnocb | ||
|
||
import ( | ||
"testing" | ||
|
||
mapset "github.com/deckarep/golang-set/v2" | ||
"github.com/smartcontractkit/libocr/commontypes" | ||
"github.com/stretchr/testify/assert" | ||
|
||
"github.com/smartcontractkit/chainlink-ccip/plugintypes" | ||
cciptypes "github.com/smartcontractkit/chainlink-common/pkg/types/ccipocr3" | ||
) | ||
|
||
func Test_validateObservedMerkleRoots(t *testing.T) { | ||
testCases := []struct { | ||
name string | ||
merkleRoots []MerkleRoot | ||
observer commontypes.OracleID | ||
observerSupportedChains mapset.Set[cciptypes.ChainSelector] | ||
expErr bool | ||
}{ | ||
{ | ||
name: "Chain not supported", | ||
merkleRoots: []MerkleRoot{ | ||
{ChainSel: 1, SeqNumRange: [2]cciptypes.SeqNum{10, 20}, RootHash: [32]byte{1, 2, 3}}, | ||
{ChainSel: 2, SeqNumRange: [2]cciptypes.SeqNum{24, 45}, RootHash: [32]byte{1, 2, 3}}, | ||
}, | ||
observer: 10, | ||
observerSupportedChains: mapset.NewSet[cciptypes.ChainSelector](1, 3, 4, 5), | ||
expErr: true, | ||
}, | ||
{ | ||
name: "Duplicate chains", | ||
merkleRoots: []MerkleRoot{ | ||
{ChainSel: 1, SeqNumRange: [2]cciptypes.SeqNum{10, 20}, RootHash: [32]byte{1, 2, 3}}, | ||
{ChainSel: 2, SeqNumRange: [2]cciptypes.SeqNum{24, 45}, RootHash: [32]byte{1, 2, 3}}, | ||
{ChainSel: 2, SeqNumRange: [2]cciptypes.SeqNum{3, 7}, RootHash: [32]byte{1, 2, 3}}, | ||
}, | ||
observer: 10, | ||
observerSupportedChains: mapset.NewSet[cciptypes.ChainSelector](1, 2), | ||
expErr: true, | ||
}, | ||
{ | ||
name: "Valid offRampMaxSeqNums", | ||
merkleRoots: []MerkleRoot{ | ||
{ChainSel: 1, SeqNumRange: [2]cciptypes.SeqNum{10, 20}, RootHash: [32]byte{1, 2, 3}}, | ||
{ChainSel: 2, SeqNumRange: [2]cciptypes.SeqNum{24, 45}, RootHash: [32]byte{1, 2, 3}}, | ||
}, | ||
observer: 10, | ||
observerSupportedChains: mapset.NewSet[cciptypes.ChainSelector](1, 2), | ||
expErr: false, | ||
}, | ||
} | ||
|
||
for _, tc := range testCases { | ||
t.Run(tc.name, func(t *testing.T) { | ||
err := validateObservedMerkleRoots(tc.merkleRoots, tc.observer, tc.observerSupportedChains) | ||
|
||
if tc.expErr { | ||
assert.Error(t, err) | ||
return | ||
} | ||
assert.NoError(t, err) | ||
}) | ||
} | ||
} | ||
|
||
func Test_validateObservedOnRampMaxSeqNums(t *testing.T) { | ||
testCases := []struct { | ||
name string | ||
onRampMaxSeqNums []plugintypes.SeqNumChain | ||
observer commontypes.OracleID | ||
observerSupportedChains mapset.Set[cciptypes.ChainSelector] | ||
expErr bool | ||
}{ | ||
{ | ||
name: "Chain not supported", | ||
onRampMaxSeqNums: []plugintypes.SeqNumChain{ | ||
{ChainSel: 1, SeqNum: 10}, | ||
{ChainSel: 2, SeqNum: 20}, | ||
}, | ||
observer: 10, | ||
observerSupportedChains: mapset.NewSet[cciptypes.ChainSelector](1, 3, 4, 5), | ||
expErr: true, | ||
}, | ||
{ | ||
name: "Duplicate chains", | ||
onRampMaxSeqNums: []plugintypes.SeqNumChain{ | ||
{ChainSel: 1, SeqNum: 10}, | ||
{ChainSel: 2, SeqNum: 20}, | ||
{ChainSel: 2, SeqNum: 33}, | ||
}, | ||
observer: 10, | ||
observerSupportedChains: mapset.NewSet[cciptypes.ChainSelector](1, 2), | ||
expErr: true, | ||
}, | ||
{ | ||
name: "Valid offRampMaxSeqNums", | ||
onRampMaxSeqNums: []plugintypes.SeqNumChain{ | ||
{ChainSel: 1, SeqNum: 10}, | ||
{ChainSel: 2, SeqNum: 20}, | ||
}, | ||
observer: 10, | ||
observerSupportedChains: mapset.NewSet[cciptypes.ChainSelector](1, 2), | ||
expErr: false, | ||
}, | ||
} | ||
|
||
for _, tc := range testCases { | ||
t.Run(tc.name, func(t *testing.T) { | ||
err := validateObservedOnRampMaxSeqNums(tc.onRampMaxSeqNums, tc.observer, tc.observerSupportedChains) | ||
|
||
if tc.expErr { | ||
assert.Error(t, err) | ||
return | ||
} | ||
assert.NoError(t, err) | ||
}) | ||
} | ||
} | ||
|
||
func Test_validateObservedOffRampMaxSeqNums(t *testing.T) { | ||
testCases := []struct { | ||
name string | ||
offRampMaxSeqNums []plugintypes.SeqNumChain | ||
observer commontypes.OracleID | ||
supportsDestChain bool | ||
expErr bool | ||
}{ | ||
{ | ||
name: "Dest chain not supported", | ||
offRampMaxSeqNums: []plugintypes.SeqNumChain{ | ||
{ChainSel: 1, SeqNum: 10}, | ||
{ChainSel: 2, SeqNum: 20}, | ||
}, | ||
observer: 10, | ||
supportsDestChain: false, | ||
expErr: true, | ||
}, | ||
{ | ||
name: "Duplicate chains", | ||
offRampMaxSeqNums: []plugintypes.SeqNumChain{ | ||
{ChainSel: 1, SeqNum: 10}, | ||
{ChainSel: 2, SeqNum: 20}, | ||
{ChainSel: 2, SeqNum: 33}, | ||
}, | ||
observer: 10, | ||
supportsDestChain: false, | ||
expErr: true, | ||
}, | ||
{ | ||
name: "Valid offRampMaxSeqNums", | ||
offRampMaxSeqNums: []plugintypes.SeqNumChain{ | ||
{ChainSel: 1, SeqNum: 10}, | ||
{ChainSel: 2, SeqNum: 20}, | ||
}, | ||
observer: 10, | ||
supportsDestChain: true, | ||
expErr: false, | ||
}, | ||
} | ||
|
||
for _, tc := range testCases { | ||
t.Run(tc.name, func(t *testing.T) { | ||
err := validateObservedOffRampMaxSeqNums(tc.offRampMaxSeqNums, tc.observer, tc.supportsDestChain) | ||
|
||
if tc.expErr { | ||
assert.Error(t, err) | ||
return | ||
} | ||
assert.NoError(t, err) | ||
}) | ||
} | ||
} | ||
|
||
func Test_validateFChain(t *testing.T) { | ||
testCases := []struct { | ||
name string | ||
fChain map[cciptypes.ChainSelector]int | ||
expErr bool | ||
}{ | ||
{ | ||
name: "FChain contains negative values", | ||
fChain: map[cciptypes.ChainSelector]int{ | ||
1: 11, | ||
2: -4, | ||
}, | ||
expErr: true, | ||
}, | ||
{ | ||
name: "FChain valid", | ||
fChain: map[cciptypes.ChainSelector]int{ | ||
12: 6, | ||
7: 9, | ||
}, | ||
expErr: false, | ||
}, | ||
} | ||
|
||
for _, tc := range testCases { | ||
t.Run(tc.name, func(t *testing.T) { | ||
err := validateFChain(tc.fChain) | ||
|
||
if tc.expErr { | ||
assert.Error(t, err) | ||
return | ||
} | ||
assert.NoError(t, err) | ||
}) | ||
} | ||
} |