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

     1  //go:build integration
     2  // +build integration
     3  
     4  package rpc
     5  
     6  import (
     7  	"testing"
     8  
     9  	"github.com/TrueBlocks/trueblocks-core/src/apps/chifra/pkg/base"
    10  	"github.com/TrueBlocks/trueblocks-core/src/apps/chifra/pkg/utils"
    11  )
    12  
    13  func TestGetContractDeployBlock(t *testing.T) {
    14  	conn := TempConnection(utils.GetTestChain())
    15  
    16  	// Finding the first block
    17  	unchainedIndex := base.HexToAddress("0x0C316b7042b419d07d343F2f4F5Bd54FF731183d")
    18  	expected := base.Blknum(14957097)
    19  	result, err := conn.GetContractDeployBlock(unchainedIndex)
    20  	if err != nil {
    21  		t.Fatal(err)
    22  	}
    23  	if result != expected {
    24  		t.Fatal("wrong result", result)
    25  	}
    26  	cached, ok := deployedCache[unchainedIndex]
    27  	if !ok {
    28  		t.Fatal("block was not cached")
    29  	}
    30  	if cached != expected {
    31  		t.Fatal("cached value is incorrect", cached)
    32  	}
    33  
    34  	// Reading from cache shortcut
    35  	fakeBlock := base.Blknum(13000000)
    36  	deployedCache[unchainedIndex] = fakeBlock
    37  	result, err = conn.GetContractDeployBlock(unchainedIndex)
    38  	if err != nil {
    39  		t.Fatal(err)
    40  	}
    41  	if result != fakeBlock {
    42  		t.Fatal("result was not read from cache", result)
    43  	}
    44  
    45  	// Error when the address is not a contract
    46  	_, err = conn.GetContractDeployBlock(base.ZeroAddr)
    47  	if err != ErrNotAContract {
    48  		t.Fatal("expected ErrNotAContract, but got", err)
    49  	}
    50  }
    51  
    52  func TestGetProxy(t *testing.T) {
    53  	//0x7cfb89d6df1b89a678dcaf42b9c262593e881e22
    54  	//0xafc2f2d803479a2af3a72022d54cc0901a0ec0d6
    55  
    56  	// 0x4Fabb145d64652a948d72533023f6E7A623C7C53
    57  	// 0x00000000441378008ea67f4284a57932b1c000a5
    58  	conn := TempConnection(utils.GetTestChain())
    59  
    60  	proxy, err := conn.GetContractProxyAt(base.HexToAddress("0x4Fabb145d64652a948d72533023f6E7A623C7C53"), base.Blknum(12983248))
    61  	if err != nil {
    62  		t.Fatal(err)
    63  	}
    64  	if proxy.IsZero() {
    65  		t.Fatal("got zero address")
    66  	}
    67  	if proxy.Hex() != "0x5864c777697bf9881220328bf2f16908c9afcd7e" {
    68  		t.Fatal("wrong proxy address:", proxy)
    69  	}
    70  }