core/types: update deposit test

This commit is contained in:
Felix Lange 2024-09-12 17:58:59 +02:00
parent 89a441f187
commit 8735cf3649

View file

@ -17,8 +17,7 @@
package types package types
import ( import (
"encoding/binary" "bytes"
"reflect"
"testing" "testing"
"github.com/ethereum/go-ethereum/accounts/abi" "github.com/ethereum/go-ethereum/accounts/abi"
@ -71,23 +70,24 @@ func FuzzUnpackIntoDeposit(f *testing.F) {
copy(sig[:], s) copy(sig[:], s)
copy(index[:], i) copy(index[:], i)
want := Deposit{ var enc []byte
PublicKey: pubkey, enc = append(enc, depositRequestType)
WithdrawalCredentials: wxCred, enc = append(enc, pubkey[:]...)
Amount: binary.LittleEndian.Uint64(amount[:]), enc = append(enc, wxCred[:]...)
Signature: sig, enc = append(enc, amount[:]...)
Index: binary.LittleEndian.Uint64(index[:]), enc = append(enc, sig[:]...)
} enc = append(enc, index[:]...)
out, err := depositABI.Pack("DepositEvent", want.PublicKey[:], want.WithdrawalCredentials[:], amount[:], want.Signature[:], index[:])
out, err := depositABI.Pack("DepositEvent", pubkey[:], wxCred[:], amount[:], sig[:], index[:])
if err != nil { if err != nil {
t.Fatalf("error packing deposit: %v", err) t.Fatalf("error packing deposit: %v", err)
} }
got, err := UnpackIntoDeposit(out[4:]) got, err := DepositLogToRequest(out[4:])
if err != nil { if err != nil {
t.Errorf("error unpacking deposit: %v", err) t.Errorf("error unpacking deposit: %v", err)
} }
if !reflect.DeepEqual(want, *got) { if !bytes.Equal(enc, got) {
t.Errorf("roundtrip failed: want %v, got %v", want, got) t.Errorf("roundtrip failed: want %x, got %x", enc, got)
} }
}) })
} }