github.com/lmittmann/w3@v0.20.0/w3vm/util_test.go (about)

     1  package w3vm_test
     2  
     3  import (
     4  	"strconv"
     5  	"testing"
     6  
     7  	"github.com/ethereum/go-ethereum/common"
     8  	"github.com/lmittmann/w3"
     9  	"github.com/lmittmann/w3/w3vm"
    10  )
    11  
    12  func TestWETHBalanceSlot(t *testing.T) {
    13  	tests := []struct {
    14  		Addr     common.Address
    15  		WantSlot common.Hash
    16  	}{
    17  		{
    18  			Addr:     w3.A("0x000000000000000000000000000000000000dEaD"),
    19  			WantSlot: w3.H("0x262bb27bbdd95c1cdc8e16957e36e38579ea44f7f6413dd7a9c75939def06b2c"),
    20  		},
    21  		{
    22  			Addr:     w3.A("0x000000000000000000000000000000000000c0Fe"),
    23  			WantSlot: w3.H("0xf68b260b81af177c0bf1a03b5d62b15aea1b486f8df26c77f33aed7538cfeb2c"),
    24  		},
    25  	}
    26  
    27  	for i, test := range tests {
    28  		t.Run(strconv.Itoa(i), func(t *testing.T) {
    29  			gotSlot := w3vm.WETHBalanceSlot(test.Addr)
    30  			if test.WantSlot != gotSlot {
    31  				t.Fatalf("want %s, got %s", test.WantSlot, gotSlot)
    32  			}
    33  		})
    34  	}
    35  }
    36  
    37  func TestWETHAllowanceSlot(t *testing.T) {
    38  	tests := []struct {
    39  		Owner    common.Address
    40  		Spender  common.Address
    41  		WantSlot common.Hash
    42  	}{
    43  		{
    44  			Owner:    w3.A("0x000000000000000000000000000000000000dEaD"),
    45  			Spender:  w3.A("0x000000000000000000000000000000000000c0Fe"),
    46  			WantSlot: w3.H("0xea3c5e9cf6f5b7aba5d41ca731cf1f8cb1373e841a1cb336cc4bfeddc27c7f8b"),
    47  		},
    48  	}
    49  
    50  	for i, test := range tests {
    51  		t.Run(strconv.Itoa(i), func(t *testing.T) {
    52  			gotSlot := w3vm.WETHAllowanceSlot(test.Owner, test.Spender)
    53  			if test.WantSlot != gotSlot {
    54  				t.Fatalf("want %s, got %s", test.WantSlot, gotSlot)
    55  			}
    56  		})
    57  	}
    58  }