Skip to content

Commit

Permalink
adding ut for keys
Browse files Browse the repository at this point in the history
  • Loading branch information
0xnogo committed Dec 18, 2024
1 parent 682a674 commit 5082358
Showing 1 changed file with 56 additions and 0 deletions.
56 changes: 56 additions & 0 deletions internal/cache/keys/keys_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
package cachekeys

import (
"testing"

"github.com/stretchr/testify/assert"

"github.com/smartcontractkit/chainlink-ccip/pkg/types/ccipocr3"
)

func TestTokenDecimals(t *testing.T) {
testCases := []struct {
name string
token ccipocr3.UnknownEncodedAddress
address string
expectedKey string
}{
{
name: "basic key generation",
token: ccipocr3.UnknownEncodedAddress("0x1234"),
address: "0xabcd",
expectedKey: "token-decimals:0x1234:0xabcd",
},
{
name: "empty token address",
token: ccipocr3.UnknownEncodedAddress(""),
address: "0xabcd",
expectedKey: "token-decimals::0xabcd",
},
{
name: "empty contract address",
token: ccipocr3.UnknownEncodedAddress("0x1234"),
address: "",
expectedKey: "token-decimals:0x1234:",
},
{
name: "both addresses empty",
token: ccipocr3.UnknownEncodedAddress(""),
address: "",
expectedKey: "token-decimals::",
},
{
name: "long addresses",
token: ccipocr3.UnknownEncodedAddress("0x1234567890abcdef1234567890abcdef12345678"),
address: "0xfedcba0987654321fedcba0987654321fedcba09",
expectedKey: "token-decimals:0x1234567890abcdef1234567890abcdef12345678:0xfedcba0987654321fedcba0987654321fedcba09",
},
}

for _, tc := range testCases {
t.Run(tc.name, func(t *testing.T) {
key := TokenDecimals(tc.token, tc.address)
assert.Equal(t, tc.expectedKey, key)
})
}
}

0 comments on commit 5082358

Please sign in to comment.