github.com/hungdoo/bot@v0.0.0-20240325145135-dd1f386f7b81/src/packages/tombplus/client_test.go (about)

     1  package tombplus
     2  
     3  import (
     4  	"crypto/ecdsa"
     5  	"math/big"
     6  	"os"
     7  	"testing"
     8  
     9  	"github.com/ethereum/go-ethereum/accounts/abi/bind"
    10  	"github.com/ethereum/go-ethereum/common"
    11  	"github.com/ethereum/go-ethereum/params"
    12  )
    13  
    14  var pk *ecdsa.PrivateKey
    15  var tombplusCli *TombplusClient
    16  
    17  func TestMain(m *testing.M) {
    18  	// Set up your fixture before running tests
    19  	setup()
    20  
    21  	// Run all the tests
    22  	exitCode := m.Run()
    23  
    24  	// Teardown your fixture after running tests
    25  	teardown()
    26  
    27  	// Exit with the code from the tests
    28  	os.Exit(exitCode)
    29  }
    30  
    31  func setup() {
    32  	// Set up your fixture data
    33  	privateKeyHex := "ac0974bec39a17e36ba4a6b4d238ff944bacb478cbed5efcae784d7bf4f2ff80" // get from anvil pub 0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266
    34  	// rpcEndpoint := "http://localhost:8545" // anvil
    35  	rpcEndpoint := "https://rpc.ftm.tools"
    36  	contractAddress := common.HexToAddress("0xA979F47480b4B598bf6a8bFA73aC0B6aEccBa505") // MasonryPlus: broadcast/TombPlusDeployment.s.sol/250/run-latest.json
    37  
    38  	var err error
    39  	pk, err = PrivateKeyFromHex(privateKeyHex)
    40  	if err != nil {
    41  		panic(err)
    42  	}
    43  
    44  	tombplusCli, err = GetClient(rpcEndpoint, contractAddress)
    45  	if err != nil {
    46  		panic(err)
    47  	}
    48  }
    49  
    50  func teardown() {
    51  	// Clean up your fixture data
    52  }
    53  
    54  func TestNewAuthorizedTransactor(t *testing.T) {
    55  	opts, err := NewAuthorizedTransactor(tombplusCli.ec, pk, 0, nil, big.NewInt(0))
    56  	if err != nil {
    57  		t.Fatal(err)
    58  	}
    59  
    60  	t.Log(opts.GasPrice)
    61  
    62  	opts, err = NewAuthorizedTransactor(tombplusCli.ec, pk, 0, new(big.Int).Mul(common.Big1, big.NewInt(params.GWei)), big.NewInt(0))
    63  	if err != nil {
    64  		t.Fatal(err)
    65  	}
    66  
    67  	t.Log(opts.GasPrice)
    68  }
    69  func TestFlipmultiple(t *testing.T) {
    70  	tx, err := tombplusCli.Flipmultiple(pk, nil, 8, true)
    71  	if err != nil {
    72  		t.Fatal(err)
    73  	}
    74  
    75  	t.Log(tx) // forge debug <txhash>
    76  }
    77  
    78  func TestClaim(t *testing.T) {
    79  	tx, err := tombplusCli.Claim(pk, nil)
    80  	if err != nil {
    81  		t.Fatal(err)
    82  	}
    83  
    84  	t.Log(tx) // forge debug <txhash>
    85  }
    86  
    87  func TestViewCalls_VoteData(t *testing.T) {
    88  
    89  	data, err := tombplusCli.Tomb.UpcomingEpochData(&bind.CallOpts{}, big.NewInt(1))
    90  	if err != nil {
    91  		t.Fatal(err)
    92  	}
    93  	t.Logf("data: %+v", data)
    94  }
    95  
    96  func TestViewCalls(t *testing.T) {
    97  	currentEpoch := tombplusCli.CurrentEpoch()
    98  	t.Logf("GameStarted: %v", tombplusCli.GameStarted())
    99  	t.Logf("currentEpoch: %v", currentEpoch)
   100  
   101  	t.Logf("MaxAllowedFutureFlips: %v", tombplusCli.MaxAllowedFutureFlips())
   102  
   103  	latestEpoch, err := tombplusCli.GetUserLastedVoteEpochId(common.HexToAddress("")) // kimchi,kimbap
   104  	if err != nil {
   105  		t.Fatal(err)
   106  	}
   107  	t.Logf("GetUserLastedVoteEpochId: %v", latestEpoch)
   108  
   109  	canFlip, err := tombplusCli.CanFlipForCurrentEpoch()
   110  	if err != nil {
   111  		t.Fatal(err)
   112  	}
   113  	t.Logf("canFlip: %v", canFlip)
   114  }