github.com/cryptotooltop/go-ethereum@v0.0.0-20231103184714-151d1922f3e5/crypto/poseidon/codehash_test.go (about)

     1  package poseidon
     2  
     3  import (
     4  	"fmt"
     5  	"testing"
     6  )
     7  
     8  func TestPoseidonCodeHash(t *testing.T) {
     9  	// nil
    10  	got := fmt.Sprintf("%s", CodeHash(nil))
    11  	want := "0x2098f5fb9e239eab3ceac3f27b81e481dc3124d55ffed523a839ee8446b64864"
    12  
    13  	if got != want {
    14  		t.Errorf("got %q, wanted %q", got, want)
    15  	}
    16  
    17  	// single byte
    18  	got = fmt.Sprintf("%s", CodeHash([]byte{0}))
    19  	want = "0x29f94b67ee4e78b2bb08da025f9943c1201a7af025a27600c2dd0a2e71c7cf8b"
    20  
    21  	if got != want {
    22  		t.Errorf("got %q, wanted %q", got, want)
    23  	}
    24  
    25  	got = fmt.Sprintf("%s", CodeHash([]byte{1}))
    26  	want = "0x246d3c06960643350a3e2d587fa16315c381635eb5ac1ac4501e195423dbf78e"
    27  
    28  	if got != want {
    29  		t.Errorf("got %q, wanted %q", got, want)
    30  	}
    31  
    32  	// 32 bytes
    33  	bytes := make([]byte, 32)
    34  	for i := range bytes {
    35  		bytes[i] = 1
    36  	}
    37  	got = fmt.Sprintf("%s", CodeHash(bytes))
    38  	want = "0x0b46d156183dffdbed8e6c6b0af139b95c058e735878ca7f4dca334e0ea8bd20"
    39  	if got != want {
    40  		t.Errorf("got %q, wanted %q", got, want)
    41  	}
    42  }