github.com/TrueBlocks/trueblocks-core/src/apps/chifra@v0.0.0-20241022031540-b362680128f7/pkg/abi/abi_test.go (about)

     1  // Copyright 2021 The TrueBlocks Authors. All rights reserved.
     2  // Use of this source code is governed by a license that can
     3  // be found in the LICENSE file.
     4  
     5  package abi
     6  
     7  import (
     8  	"fmt"
     9  	"strings"
    10  	"testing"
    11  
    12  	"github.com/ethereum/go-ethereum/accounts/abi"
    13  	"github.com/ethereum/go-ethereum/common"
    14  )
    15  
    16  func Test_Abi_Decode(t *testing.T) {
    17  	const definition = `[{"constant":true,"inputs":[{"name":"","type":"address"}],"name":"isBar","outputs":[{"name":"","type":"bool"}],"type":"function"}]`
    18  
    19  	abi, err := abi.JSON(strings.NewReader(definition))
    20  	if err != nil {
    21  		panic(err)
    22  	}
    23  	out, err := abi.Pack("isBar", common.HexToAddress("01"))
    24  	if err != nil {
    25  		t.Error(err) // panic(err)
    26  	}
    27  	fmt.Printf("%x\n", out)
    28  
    29  	i, _ := abi.Unpack("isBar", out[4:])
    30  	fmt.Printf("%v\n", i)
    31  }