github.com/hashgraph/hedera-sdk-go/v2@v2.48.0/ethereum_data_unit_test.go (about)

     1  //go:build all || unit
     2  // +build all unit
     3  
     4  package hedera
     5  
     6  /*-
     7   *
     8   * Hedera Go SDK
     9   *
    10   * Copyright (C) 2020 - 2024 Hedera Hashgraph, LLC
    11   *
    12   * Licensed under the Apache License, Version 2.0 (the "License");
    13   * you may not use this file except in compliance with the License.
    14   * You may obtain a copy of the License at
    15   *
    16   *      http://www.apache.org/licenses/LICENSE-2.0
    17   *
    18   * Unless required by applicable law or agreed to in writing, software
    19   * distributed under the License is distributed on an "AS IS" BASIS,
    20   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    21   * See the License for the specific language governing permissions and
    22   * limitations under the License.
    23   *
    24   */
    25  
    26  import (
    27  	"encoding/hex"
    28  	"testing"
    29  
    30  	"github.com/stretchr/testify/require"
    31  )
    32  
    33  func TestUnitEthereumData(t *testing.T) {
    34  	t.Parallel()
    35  
    36  	byt, err := hex.DecodeString("02f87082012a022f2f83018000947e3a9eaf9bcc39e2ffa38eb30bf7a93feacbc181880de0b6b3a764000083123456c001a0df48f2efd10421811de2bfb125ab75b2d3c44139c4642837fb1fccce911fd479a01aaf7ae92bee896651dfc9d99ae422a296bf5d9f1ca49b2d96d82b79eb112d66")
    37  	require.NoError(t, err)
    38  	b, err := EthereumTransactionDataFromBytes(byt)
    39  	require.NoError(t, err)
    40  	k, err := b.ToBytes()
    41  	require.Equal(t, hex.EncodeToString(k), "02f87082012a022f2f83018000947e3a9eaf9bcc39e2ffa38eb30bf7a93feacbc181880de0b6b3a764000083123456c001a0df48f2efd10421811de2bfb125ab75b2d3c44139c4642837fb1fccce911fd479a01aaf7ae92bee896651dfc9d99ae422a296bf5d9f1ca49b2d96d82b79eb112d66")
    42  }
    43  
    44  func TestUnitEthereumJson(t *testing.T) {
    45  	t.Parallel()
    46  
    47  	byt, err := hex.DecodeString("02f87082012a022f2f83018000947e3a9eaf9bcc39e2ffa38eb30bf7a93feacbc181880de0b6b3a764000083123456c001a0df48f2efd10421811de2bfb125ab75b2d3c44139c4642837fb1fccce911fd479a01aaf7ae92bee896651dfc9d99ae422a296bf5d9f1ca49b2d96d82b79eb112d66")
    48  	require.NoError(t, err)
    49  	b, err := EthereumTransactionDataFromBytes(byt)
    50  	require.NoError(t, err)
    51  	k, err := b.ToJson()
    52  	require.Equal(t, string(k), "{\"ChainID\":298,\"Nonce\":2,\"GasTipCap\":47,\"GasFeeCap\":47,\"Gas\":98304,\"To\":\"0x7e3a9eaf9bcc39e2ffa38eb30bf7a93feacbc181\",\"Value\":1000000000000000000,\"Data\":\"EjRW\",\"AccessList\":[],\"v\":1,\"r\":100994654910787593347140909067229841565925886199208140719315441876745360233593,\"s\":12070180598849582105957204602453860723012110108194703753759584093273689501030}")
    53  	second, err := EthereumTransactionDataFromJson(k)
    54  	require.NoError(t, err)
    55  	bytSecond, err := second.ToBytes()
    56  	require.NoError(t, err)
    57  	require.Equal(t, hex.EncodeToString(bytSecond), "02f87082012a022f2f83018000947e3a9eaf9bcc39e2ffa38eb30bf7a93feacbc181880de0b6b3a764000083123456c001a0df48f2efd10421811de2bfb125ab75b2d3c44139c4642837fb1fccce911fd479a01aaf7ae92bee896651dfc9d99ae422a296bf5d9f1ca49b2d96d82b79eb112d66")
    58  }