@@ -1594,3 +1594,132 @@ func TestTokenInfoMapNilHandling(t *testing.T) {
15941594 assert .Len (t , convertedMap , 0 )
15951595 })
15961596}
1597+
1598+ // TestExtraDataCodecBundleConversion tests the map conversion logic used by ExtraDataCodecBundle methods
1599+ // This test verifies that round-trip conversion preserves structure and semantic meaning
1600+ func TestExtraDataCodecBundleConversion (t * testing.T ) {
1601+ t .Run ("Nil map round-trip" , func (t * testing.T ) {
1602+ // Test that nil maps remain nil after round-trip
1603+ pbMap , err := goMapToPbMap (nil )
1604+ require .NoError (t , err )
1605+
1606+ result , err := pbMapToGoMap (pbMap )
1607+ require .NoError (t , err )
1608+ assert .Nil (t , result , "nil input should result in nil output" )
1609+ })
1610+
1611+ t .Run ("Empty map round-trip" , func (t * testing.T ) {
1612+ // Test that empty maps remain empty after round-trip
1613+ emptyMap := map [string ]any {}
1614+ pbMap , err := goMapToPbMap (emptyMap )
1615+ require .NoError (t , err )
1616+
1617+ result , err := pbMapToGoMap (pbMap )
1618+ require .NoError (t , err )
1619+ assert .NotNil (t , result , "empty map should not become nil" )
1620+ assert .Equal (t , 0 , len (result ), "empty map should remain empty" )
1621+ })
1622+
1623+ t .Run ("ExtraArgs-like data structure preservation" , func (t * testing.T ) {
1624+ // Test typical ExtraArgs structure with basic types
1625+ input := map [string ]any {
1626+ "gasLimit" : uint64 (100000 ),
1627+ "gasPrice" : uint64 (20000000000 ),
1628+ "enabled" : true ,
1629+ "data" : []byte {0x01 , 0x02 , 0x03 },
1630+ }
1631+
1632+ pbMap , err := goMapToPbMap (input )
1633+ require .NoError (t , err , "conversion to protobuf should succeed" )
1634+
1635+ result , err := pbMapToGoMap (pbMap )
1636+ require .NoError (t , err , "conversion from protobuf should succeed" )
1637+
1638+ // Verify structure is preserved
1639+ assert .Equal (t , len (input ), len (result ), "map size should be preserved" )
1640+
1641+ // Verify all keys exist
1642+ for key := range input {
1643+ assert .Contains (t , result , key , "key %s should exist after round-trip" , key )
1644+ }
1645+
1646+ // Verify specific values that should be exactly preserved
1647+ assert .Equal (t , input ["enabled" ], result ["enabled" ], "bool values should be preserved" )
1648+ assert .Equal (t , input ["data" ], result ["data" ], "byte slice values should be preserved" )
1649+
1650+ // For numeric values, verify semantic equivalence (protobuf may normalize types)
1651+ assert .Equal (t , fmt .Sprintf ("%v" , input ["gasLimit" ]), fmt .Sprintf ("%v" , result ["gasLimit" ]), "gasLimit should be semantically equal" )
1652+ assert .Equal (t , fmt .Sprintf ("%v" , input ["gasPrice" ]), fmt .Sprintf ("%v" , result ["gasPrice" ]), "gasPrice should be semantically equal" )
1653+ })
1654+
1655+ t .Run ("BigInt preservation" , func (t * testing.T ) {
1656+ // Test various BigInt values that are commonly used in ExtraArgs/DestExecData
1657+ input := map [string ]any {
1658+ "zero" : big .NewInt (0 ),
1659+ "small" : big .NewInt (42 ),
1660+ "large" : big .NewInt (1000000000000000000 ), // 1 ETH in wei
1661+ "negative" : big .NewInt (- 123456789 ),
1662+ }
1663+
1664+ pbMap , err := goMapToPbMap (input )
1665+ require .NoError (t , err )
1666+
1667+ result , err := pbMapToGoMap (pbMap )
1668+ require .NoError (t , err )
1669+
1670+ // Verify all BigInt values are preserved exactly
1671+ for key , originalVal := range input {
1672+ resultVal , exists := result [key ]
1673+ require .True (t , exists , "key %s should exist" , key )
1674+
1675+ originalBigInt := originalVal .(* big.Int )
1676+ resultBigInt , ok := resultVal .(* big.Int )
1677+ require .True (t , ok , "result[%s] should be *big.Int" , key )
1678+ assert .Equal (t , originalBigInt .String (), resultBigInt .String (), "BigInt value should be preserved for key %s" , key )
1679+ }
1680+ })
1681+
1682+ t .Run ("Nested structure preservation" , func (t * testing.T ) {
1683+ // Test nested maps and arrays as might appear in DestExecData
1684+ input := map [string ]any {
1685+ "version" : uint32 (1 ),
1686+ "config" : map [string ]any {
1687+ "maxGas" : uint64 (500000 ),
1688+ "multiplier" : float64 (1.5 ),
1689+ },
1690+ "amounts" : []any {
1691+ big .NewInt (1000 ),
1692+ big .NewInt (2000 ),
1693+ },
1694+ }
1695+
1696+ pbMap , err := goMapToPbMap (input )
1697+ require .NoError (t , err )
1698+
1699+ result , err := pbMapToGoMap (pbMap )
1700+ require .NoError (t , err )
1701+
1702+ // Verify top-level structure
1703+ assert .Equal (t , len (input ), len (result ), "top-level map size should be preserved" )
1704+
1705+ // Verify nested map structure
1706+ configResult , ok := result ["config" ].(map [string ]any )
1707+ require .True (t , ok , "config should remain a map" )
1708+ configInput := input ["config" ].(map [string ]any )
1709+ assert .Equal (t , len (configInput ), len (configResult ), "nested map size should be preserved" )
1710+
1711+ // Verify array structure
1712+ amountsResult , ok := result ["amounts" ].([]any )
1713+ require .True (t , ok , "amounts should remain an array" )
1714+ amountsInput := input ["amounts" ].([]any )
1715+ assert .Equal (t , len (amountsInput ), len (amountsResult ), "array size should be preserved" )
1716+
1717+ // Verify BigInt values in array are preserved
1718+ for i , originalAmount := range amountsInput {
1719+ originalBigInt := originalAmount .(* big.Int )
1720+ resultBigInt , ok := amountsResult [i ].(* big.Int )
1721+ require .True (t , ok , "array element should remain *big.Int" )
1722+ assert .Equal (t , originalBigInt .String (), resultBigInt .String (), "BigInt value should be preserved" )
1723+ }
1724+ })
1725+ }
0 commit comments