Skip to content

Commit

Permalink
Update ccip reader nonce tests.
Browse files Browse the repository at this point in the history
  • Loading branch information
winder committed Aug 28, 2024
1 parent c56b604 commit b33e379
Show file tree
Hide file tree
Showing 4 changed files with 53 additions and 38 deletions.
8 changes: 4 additions & 4 deletions contracts/src/v0.8/ccip/test/helpers/CCIPReaderTester.sol
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ contract CCIPReaderTester {

mapping(uint64 sourceChainSelector => OffRamp.SourceChainConfig sourceChainConfig) internal s_sourceChainConfigs;
mapping(uint64 destChainSelector => uint64 sequenceNumber) internal s_destChainSeqNrs;
mapping(bytes sender => uint64 nonce) internal s_senderNonce;
mapping(uint64 sourceChainSelector => mapping(bytes sender => uint64 nonce)) internal s_senderNonce;

/// @notice Gets the next sequence number to be used in the onRamp
/// @param destChainSelector The destination chain selector
Expand All @@ -30,11 +30,11 @@ contract CCIPReaderTester {
/// @param sender The encoded sender address.
/// @return inboundNonce The inbound nonce.
function getInboundNonce(uint64 sourceChainSelector, bytes calldata sender) external view returns (uint64) {
return s_senderNonce[sender];
return s_senderNonce[sourceChainSelector][sender];
}

function testhelper_setInboundNonce(uint64 testNonce, bytes calldata sender) external {
s_senderNonce[sender] = testNonce;
function setInboundNonce(uint64 sourceChainSelector, uint64 testNonce, bytes calldata sender) external {
s_senderNonce[sourceChainSelector][sender] = testNonce;
}

function getSourceChainConfig(uint64 sourceChainSelector) external view returns (OffRamp.SourceChainConfig memory) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -355,9 +355,20 @@ func TestCCIPReader_GetExpectedNextSequenceNumber(t *testing.T) {

func TestCCIPReader_Nonces(t *testing.T) {
ctx := testutils.Context(t)
addrs := []common.Address{utils.RandomAddress(), utils.RandomAddress()}
nonces := []uint64{10, 9999}
assert.Equal(t, len(addrs), len(nonces), "addrs and nonces should have the same length")
var nonces = map[cciptypes.ChainSelector]map[common.Address]uint64{
chainS1: {
utils.RandomAddress(): 10,
utils.RandomAddress(): 20,
},
chainS2: {
utils.RandomAddress(): 30,
utils.RandomAddress(): 40,
},
chainS3: {
utils.RandomAddress(): 50,
utils.RandomAddress(): 60,
},
}

cfg := evmtypes.ChainReaderConfig{
Contracts: map[string]evmtypes.ChainContractReader{
Expand All @@ -375,25 +386,29 @@ func TestCCIPReader_Nonces(t *testing.T) {

s := testSetup(ctx, t, chainD, chainD, nil, cfg)

for i := range addrs {
_, err := s.contract.TesthelperSetInboundNonce(s.auth, nonces[i], addrs[i].Bytes())
assert.NoError(t, err)
// Add some nonces. The test contract isn't using source
for chain, addrs := range nonces {
for addr, nonce := range addrs {
_, err := s.contract.SetInboundNonce(s.auth, uint64(chain), nonce, addr.Bytes())
assert.NoError(t, err)
}
}
s.sb.Commit()

//val, err := s.contract.GetInboundNonce(&bind.CallOpts{Context: ctx}, 10, addr.Bytes())
//fmt.Println(val, err)
for sourceChain, addrs := range nonces {

var addrQuery []string
for _, addr := range addrs {
addrQuery = append(addrQuery, addr.String())
}
var addrQuery []string
for addr := range addrs {
addrQuery = append(addrQuery, addr.String())
}
addrQuery = append(addrQuery, utils.RandomAddress().String())

results, err := s.reader.Nonces(ctx, chainS1, chainD, addrQuery)
assert.NoError(t, err)
assert.Len(t, results, 1)
for i := range addrs {
assert.Equal(t, nonces[i], results[addrs[i].String()])
results, err := s.reader.Nonces(ctx, sourceChain, chainD, addrQuery)
assert.NoError(t, err)
assert.Len(t, results, len(addrQuery))
for addr, nonce := range addrs {
assert.Equal(t, nonce, results[addr.String()])
}
}
}

Expand Down
Loading

0 comments on commit b33e379

Please sign in to comment.