@@ -206,80 +206,6 @@ func TestTransformERC20(t *testing.T) {
206206 }
207207}
208208
209- func TestUpdateITxStatus (t * testing.T ) {
210- tests := []struct {
211- name string
212- internalTx []* types.Eth1InternalTransaction
213- indexedTx * types.Eth1TransactionIndexed
214- expectedStatus types.StatusType
215- expectedErrorMsg string
216- }{
217- {
218- name : "no internal transactions" ,
219- internalTx : []* types.Eth1InternalTransaction {},
220- indexedTx : & types.Eth1TransactionIndexed {
221- Status : types .StatusType_SUCCESS ,
222- },
223- expectedStatus : types .StatusType_SUCCESS ,
224- expectedErrorMsg : "" ,
225- },
226- {
227- name : "internal transaction with error" ,
228- internalTx : []* types.Eth1InternalTransaction {
229- {
230- ErrorMsg : "fail" ,
231- },
232- },
233- indexedTx : & types.Eth1TransactionIndexed {
234- Status : types .StatusType_SUCCESS ,
235- },
236- expectedStatus : types .StatusType_PARTIAL ,
237- expectedErrorMsg : "fail" ,
238- },
239- {
240- name : "internal transaction with error and status failed" ,
241- internalTx : []* types.Eth1InternalTransaction {
242- {
243- ErrorMsg : "fail" ,
244- },
245- },
246- indexedTx : & types.Eth1TransactionIndexed {
247- Status : types .StatusType_FAILED ,
248- },
249- expectedStatus : types .StatusType_FAILED ,
250- expectedErrorMsg : "fail" ,
251- },
252- {
253- name : "multiple internal transactions, one with error" ,
254- internalTx : []* types.Eth1InternalTransaction {
255- {
256- ErrorMsg : "" ,
257- },
258- {
259- ErrorMsg : "fail" ,
260- },
261- },
262- indexedTx : & types.Eth1TransactionIndexed {
263- Status : types .StatusType_SUCCESS ,
264- },
265- expectedStatus : types .StatusType_PARTIAL ,
266- expectedErrorMsg : "fail" ,
267- },
268- }
269-
270- for _ , tt := range tests {
271- t .Run (tt .name , func (t * testing.T ) {
272- updateITxStatus (tt .internalTx , tt .indexedTx )
273- if tt .indexedTx .Status != tt .expectedStatus {
274- t .Errorf ("got status %v, want %v" , tt .indexedTx .Status , tt .expectedStatus )
275- }
276- if tt .indexedTx .ErrorMsg != tt .expectedErrorMsg {
277- t .Errorf ("got error message %v, want %v" , tt .indexedTx .ErrorMsg , tt .expectedErrorMsg )
278- }
279- })
280- }
281- }
282-
283209func TestIsValidERC20Log (t * testing.T ) {
284210 tests := []struct {
285211 name string
@@ -811,6 +737,219 @@ func TestGetERC20TransferValue(t *testing.T) {
811737 }
812738}
813739
740+ func TestGetERC1155TransferIDs (t * testing.T ) {
741+ tests := []struct {
742+ name string
743+ idList []* big.Int
744+ expected [][]byte
745+ }{
746+ {
747+ name : "single ID" ,
748+ idList : []* big.Int {
749+ big .NewInt (1 ),
750+ },
751+ expected : [][]byte {
752+ big .NewInt (1 ).Bytes (),
753+ },
754+ },
755+ {
756+ name : "multiple IDs" ,
757+ idList : []* big.Int {
758+ big .NewInt (1 ),
759+ big .NewInt (2 ),
760+ big .NewInt (3 ),
761+ },
762+ expected : [][]byte {
763+ big .NewInt (1 ).Bytes (),
764+ big .NewInt (2 ).Bytes (),
765+ big .NewInt (3 ).Bytes (),
766+ },
767+ },
768+ {
769+ name : "empty ID list" ,
770+ idList : []* big.Int {},
771+ expected : [][]byte {},
772+ },
773+ }
774+
775+ for _ , tt := range tests {
776+ t .Run (tt .name , func (t * testing.T ) {
777+ result := getERC1155TransferIDs (tt .idList )
778+ if len (result ) != len (tt .expected ) {
779+ t .Errorf ("got %v IDs, want %v IDs" , len (result ), len (tt .expected ))
780+ }
781+ for i := range result {
782+ if ! bytes .Equal (result [i ], tt .expected [i ]) {
783+ t .Errorf ("got ID %v, want %v" , result [i ], tt .expected [i ])
784+ }
785+ }
786+ })
787+ }
788+ }
789+
790+ func TestGetERC1155TransferValues (t * testing.T ) {
791+ tests := []struct {
792+ name string
793+ values []* big.Int
794+ expected [][]byte
795+ }{
796+ {
797+ name : "single value" ,
798+ values : []* big.Int {
799+ big .NewInt (1 ),
800+ },
801+ expected : [][]byte {
802+ big .NewInt (1 ).Bytes (),
803+ },
804+ },
805+ {
806+ name : "multiple values" ,
807+ values : []* big.Int {
808+ big .NewInt (1 ),
809+ big .NewInt (2 ),
810+ big .NewInt (3 ),
811+ },
812+ expected : [][]byte {
813+ big .NewInt (1 ).Bytes (),
814+ big .NewInt (2 ).Bytes (),
815+ big .NewInt (3 ).Bytes (),
816+ },
817+ },
818+ {
819+ name : "empty values list" ,
820+ values : []* big.Int {},
821+ expected : [][]byte {},
822+ },
823+ }
824+
825+ for _ , tt := range tests {
826+ t .Run (tt .name , func (t * testing.T ) {
827+ result := getERC1155TransferValues (tt .values )
828+ if len (result ) != len (tt .expected ) {
829+ t .Errorf ("got %v values, want %v values" , len (result ), len (tt .expected ))
830+ }
831+ for i := range result {
832+ if ! bytes .Equal (result [i ], tt .expected [i ]) {
833+ t .Errorf ("got value %v, want %v" , result [i ], tt .expected [i ])
834+ }
835+ }
836+ })
837+ }
838+ }
839+
840+ func TestUpdateITxStatus (t * testing.T ) {
841+ tests := []struct {
842+ name string
843+ internalTx []* types.Eth1InternalTransaction
844+ indexedTx * types.Eth1TransactionIndexed
845+ expectedStatus types.StatusType
846+ expectedErrorMsg string
847+ }{
848+ {
849+ name : "no internal transactions" ,
850+ internalTx : []* types.Eth1InternalTransaction {},
851+ indexedTx : & types.Eth1TransactionIndexed {
852+ Status : types .StatusType_SUCCESS ,
853+ },
854+ expectedStatus : types .StatusType_SUCCESS ,
855+ expectedErrorMsg : "" ,
856+ },
857+ {
858+ name : "internal transaction with error" ,
859+ internalTx : []* types.Eth1InternalTransaction {
860+ {
861+ ErrorMsg : "fail" ,
862+ },
863+ },
864+ indexedTx : & types.Eth1TransactionIndexed {
865+ Status : types .StatusType_SUCCESS ,
866+ },
867+ expectedStatus : types .StatusType_PARTIAL ,
868+ expectedErrorMsg : "fail" ,
869+ },
870+ {
871+ name : "internal transaction with error and status failed" ,
872+ internalTx : []* types.Eth1InternalTransaction {
873+ {
874+ ErrorMsg : "fail" ,
875+ },
876+ },
877+ indexedTx : & types.Eth1TransactionIndexed {
878+ Status : types .StatusType_FAILED ,
879+ },
880+ expectedStatus : types .StatusType_FAILED ,
881+ expectedErrorMsg : "fail" ,
882+ },
883+ {
884+ name : "multiple internal transactions, one with error" ,
885+ internalTx : []* types.Eth1InternalTransaction {
886+ {
887+ ErrorMsg : "" ,
888+ },
889+ {
890+ ErrorMsg : "fail" ,
891+ },
892+ },
893+ indexedTx : & types.Eth1TransactionIndexed {
894+ Status : types .StatusType_SUCCESS ,
895+ },
896+ expectedStatus : types .StatusType_PARTIAL ,
897+ expectedErrorMsg : "fail" ,
898+ },
899+ }
900+
901+ for _ , tt := range tests {
902+ t .Run (tt .name , func (t * testing.T ) {
903+ updateITxStatus (tt .internalTx , tt .indexedTx )
904+ if tt .indexedTx .Status != tt .expectedStatus {
905+ t .Errorf ("got status %v, want %v" , tt .indexedTx .Status , tt .expectedStatus )
906+ }
907+ if tt .indexedTx .ErrorMsg != tt .expectedErrorMsg {
908+ t .Errorf ("got error message %v, want %v" , tt .indexedTx .ErrorMsg , tt .expectedErrorMsg )
909+ }
910+ })
911+ }
912+ }
913+
914+ func TestCalculateTxFee (t * testing.T ) {
915+ tests := []struct {
916+ name string
917+ tx * types.Eth1Transaction
918+ baseFee []byte
919+ expected * big.Int
920+ }{
921+ {
922+ name : "transaction with no base fee" ,
923+ tx : & types.Eth1Transaction {
924+ GasPrice : big .NewInt (10 ).Bytes (),
925+ GasUsed : 1000 ,
926+ },
927+ baseFee : []byte {},
928+ expected : big .NewInt (10 * 1000 ),
929+ },
930+ {
931+ name : "transaction with priority and base fee" ,
932+ tx : & types.Eth1Transaction {
933+ GasPrice : big .NewInt (100 ).Bytes (),
934+ MaxPriorityFeePerGas : big .NewInt (10 ).Bytes (),
935+ MaxFeePerGas : big .NewInt (200 ).Bytes (),
936+ GasUsed : 1000 ,
937+ },
938+ baseFee : big .NewInt (50 ).Bytes (),
939+ expected : big .NewInt (10 * 1000 ),
940+ },
941+ }
942+
943+ for _ , tt := range tests {
944+ t .Run (tt .name , func (t * testing.T ) {
945+ result := calculateTxFee (tt .tx , tt .baseFee )
946+ if result .Cmp (tt .expected ) != 0 {
947+ t .Errorf ("got %v, want %v" , result , tt .expected )
948+ }
949+ })
950+ }
951+ }
952+
814953func addPrefix (b []byte , length int ) []byte {
815954 for len (b ) != length {
816955 b = append ([]byte {0 }, b ... )
0 commit comments