@@ -951,52 +951,52 @@ func TestMessagesByTokenIDErrorHandling(t *testing.T) {
951951 })
952952}
953953
954- // TestTokenUpdatesConversion tests the token updates conversion functions
955- func TestTokenUpdatesConversion (t * testing.T ) {
954+ // TestTokenUpdatesUnixConversion tests the TimestampedUnixBig token updates conversion functions
955+ func TestTokenUpdatesUnixConversion (t * testing.T ) {
956956 testTime := time .Date (2024 , 1 , 15 , 12 , 0 , 0 , 0 , time .UTC )
957957
958958 testCases := []struct {
959959 name string
960- updates map [ccipocr3.UnknownEncodedAddress ]ccipocr3.TimestampedBig
960+ updates map [ccipocr3.UnknownEncodedAddress ]ccipocr3.TimestampedUnixBig
961961 }{
962962 {
963- name : "Token updates with multiple tokens" ,
964- updates : map [ccipocr3.UnknownEncodedAddress ]ccipocr3.TimestampedBig {
963+ name : "Unix token updates with multiple tokens" ,
964+ updates : map [ccipocr3.UnknownEncodedAddress ]ccipocr3.TimestampedUnixBig {
965965 ccipocr3 .UnknownEncodedAddress ("token1" ): {
966- Timestamp : testTime ,
967- Value : ccipocr3 . NewBigInt ( big .NewInt (1500000 ) ),
966+ Timestamp : uint32 ( testTime . Unix ()) ,
967+ Value : big .NewInt (1500000 ),
968968 },
969969 ccipocr3 .UnknownEncodedAddress ("token2" ): {
970- Timestamp : testTime .Add (time .Hour ),
971- Value : ccipocr3 . NewBigInt ( big .NewInt (2500000 ) ),
970+ Timestamp : uint32 ( testTime .Add (time .Hour ). Unix () ),
971+ Value : big .NewInt (2500000 ),
972972 },
973973 ccipocr3 .UnknownEncodedAddress ("token3" ): {
974- Timestamp : testTime .Add (2 * time .Hour ),
975- Value : ccipocr3 . NewBigInt ( big .NewInt (750000 ) ),
974+ Timestamp : uint32 ( testTime .Add (2 * time .Hour ). Unix () ),
975+ Value : big .NewInt (750000 ),
976976 },
977977 },
978978 },
979979 {
980- name : "Empty token updates" ,
981- updates : map [ccipocr3.UnknownEncodedAddress ]ccipocr3.TimestampedBig {},
980+ name : "Empty unix token updates" ,
981+ updates : map [ccipocr3.UnknownEncodedAddress ]ccipocr3.TimestampedUnixBig {},
982982 },
983983 {
984- name : "Token update with zero value" ,
985- updates : map [ccipocr3.UnknownEncodedAddress ]ccipocr3.TimestampedBig {
984+ name : "Unix token update with zero value" ,
985+ updates : map [ccipocr3.UnknownEncodedAddress ]ccipocr3.TimestampedUnixBig {
986986 ccipocr3 .UnknownEncodedAddress ("zero-token" ): {
987- Timestamp : testTime ,
988- Value : ccipocr3 . NewBigInt ( big .NewInt (0 ) ),
987+ Timestamp : uint32 ( testTime . Unix ()) ,
988+ Value : big .NewInt (0 ),
989989 },
990990 },
991991 },
992992 {
993- name : "Token update with large value" ,
994- updates : map [ccipocr3.UnknownEncodedAddress ]ccipocr3.TimestampedBig {
993+ name : "Unix token update with large value" ,
994+ updates : map [ccipocr3.UnknownEncodedAddress ]ccipocr3.TimestampedUnixBig {
995995 ccipocr3 .UnknownEncodedAddress ("large-token" ): {
996- Timestamp : testTime ,
997- Value : func () ccipocr3. BigInt {
996+ Timestamp : uint32 ( testTime . Unix ()) ,
997+ Value : func () * big. Int {
998998 val , _ := new (big.Int ).SetString ("999999999999999999999999999999" , 10 )
999- return ccipocr3 . NewBigInt ( val )
999+ return val
10001000 }(),
10011001 },
10021002 },
@@ -1006,7 +1006,7 @@ func TestTokenUpdatesConversion(t *testing.T) {
10061006 for _ , tc := range testCases {
10071007 t .Run (tc .name , func (t * testing.T ) {
10081008 // Convert Go -> Protobuf
1009- pbMap := tokenUpdatesToPb (tc .updates )
1009+ pbMap := tokenUpdatesUnixToPb (tc .updates )
10101010
10111011 if tc .updates == nil {
10121012 assert .Nil (t , pbMap )
@@ -1021,63 +1021,62 @@ func TestTokenUpdatesConversion(t *testing.T) {
10211021 pbUpdate , exists := pbMap [string (token )]
10221022 require .True (t , exists , "token %s should exist in protobuf map" , string (token ))
10231023 require .NotNil (t , pbUpdate )
1024- require .NotNil (t , pbUpdate .Timestamp )
10251024 require .NotNil (t , pbUpdate .Value )
10261025
1027- assert .Equal (t , update .Timestamp . Unix () , pbUpdate .Timestamp . AsTime (). Unix () )
1028- assert .Equal (t , update .Value .Int . Bytes (), pbUpdate .Value .Value )
1026+ assert .Equal (t , update .Timestamp , pbUpdate .Timestamp )
1027+ assert .Equal (t , update .Value .Bytes (), pbUpdate .Value .Value )
10291028 }
10301029
10311030 // Convert Protobuf -> Go (round-trip)
1032- convertedMap := pbToTokenUpdates (pbMap )
1031+ convertedMap := pbToTokenUpdatesUnix (pbMap )
10331032
10341033 // Verify round-trip conversion
10351034 assert .Equal (t , len (tc .updates ), len (convertedMap ))
10361035 for token , originalUpdate := range tc .updates {
10371036 convertedUpdate , exists := convertedMap [token ]
10381037 require .True (t , exists , "token %s should exist in converted map" , string (token ))
10391038
1040- // Compare timestamps (allowing for some precision loss in conversion)
1041- assert .Equal (t , originalUpdate .Timestamp .Unix (), convertedUpdate .Timestamp .Unix ())
1042- assert .Equal (t , originalUpdate .Value .Int .String (), convertedUpdate .Value .Int .String ())
1039+ assert .Equal (t , originalUpdate .Timestamp , convertedUpdate .Timestamp )
1040+ assert .Equal (t , originalUpdate .Value .String (), convertedUpdate .Value .String ())
10431041 }
10441042 })
10451043 }
10461044}
10471045
1048- func TestTokenUpdatesNilHandling (t * testing.T ) {
1049- t .Run ("nil token updates to protobuf" , func (t * testing.T ) {
1050- pbMap := tokenUpdatesToPb (nil )
1046+ func TestTokenUpdatesUnixNilHandling (t * testing.T ) {
1047+ t .Run ("nil unix token updates to protobuf" , func (t * testing.T ) {
1048+ pbMap := tokenUpdatesUnixToPb (nil )
10511049 assert .Nil (t , pbMap )
10521050 })
10531051
1054- t .Run ("nil protobuf map to token updates" , func (t * testing.T ) {
1055- updates := pbToTokenUpdates (nil )
1052+ t .Run ("nil protobuf map to unix token updates" , func (t * testing.T ) {
1053+ updates := pbToTokenUpdatesUnix (nil )
10561054 assert .Nil (t , updates )
10571055 })
10581056
1059- t .Run ("empty protobuf map to token updates" , func (t * testing.T ) {
1060- emptyPbMap := make (map [string ]* ccipocr3pb.TimestampedBig )
1061- updates := pbToTokenUpdates (emptyPbMap )
1057+ t .Run ("empty protobuf map to unix token updates" , func (t * testing.T ) {
1058+ emptyPbMap := make (map [string ]* ccipocr3pb.TimestampedUnixBig )
1059+ updates := pbToTokenUpdatesUnix (emptyPbMap )
10621060 require .NotNil (t , updates )
10631061 assert .Equal (t , 0 , len (updates ))
10641062 })
10651063
1066- t .Run ("protobuf map with nil timestamp " , func (t * testing.T ) {
1067- pbMap := map [string ]* ccipocr3pb.TimestampedBig {
1064+ t .Run ("protobuf map with nil value " , func (t * testing.T ) {
1065+ pbMap := map [string ]* ccipocr3pb.TimestampedUnixBig {
10681066 "test-token" : {
1069- Timestamp : nil ,
1070- Value : & ccipocr3pb. BigInt { Value : [] byte { 0x01 }} ,
1067+ Timestamp : 1705320000 , // Some valid unix timestamp
1068+ Value : nil ,
10711069 },
10721070 }
10731071
10741072 // Should not panic and handle gracefully
1075- updates := pbToTokenUpdates (pbMap )
1073+ updates := pbToTokenUpdatesUnix (pbMap )
10761074 require .NotNil (t , updates )
10771075 require .Contains (t , updates , ccipocr3 .UnknownEncodedAddress ("test-token" ))
10781076
1079- // When timestamp is nil, should default to zero time
1080- update := updates [ccipocr3 .UnknownEncodedAddress ("test-token" )]
1081- assert .True (t , update .Timestamp .IsZero ())
1077+ // When value is nil, should default to zero big.Int
1078+ update := updates [("test-token" )]
1079+ assert .Equal (t , uint32 (1705320000 ), update .Timestamp )
1080+ assert .Equal (t , big .NewInt (0 ), update .Value )
10821081 })
10831082}
0 commit comments