Пример #1
0
func TestEncodeZero(t *testing.T) {
	b, _ := rlp.EncodeToBytes(NewValue(0))
	exp := []byte{0xc0}
	if bytes.Compare(b, exp) == 0 {
		t.Error("Expected", exp, "got", b)
	}
}
Пример #2
0
func TestEncodeDecodeBytes(t *testing.T) {
	bv := NewValue([]interface{}{[]byte{1, 2, 3, 4, 5}, []byte{6}})
	b, _ := rlp.EncodeToBytes(bv)
	val := NewValueFromBytes(b)
	if !bv.Cmp(val) {
		t.Errorf("Expected %#v, got %#v", bv, val)
	}
}
Пример #3
0
// Creates an ethereum address from a create transaction
// If the tx doesn't create a contract, CreateAddress returns nil
func (tx *Transaction) CreateAddress() []byte {
	if tx.Recipient != nil {
		return nil
	}
	data, _ := rlp.EncodeToBytes([]interface{}{tx.from, tx.Nonce})
	hw := sha3.NewKeccak256()
	hw.Write(data)
	b := hw.Sum(nil)
	return b[12:]
}
Пример #4
0
func TestRlpValueEncoding(t *testing.T) {
	val := EmptyValue()
	val.AppendList().Append(byte(1)).Append(byte(2)).Append(byte(3))
	val.Append("4").AppendList().Append(byte(5))

	res, err := rlp.EncodeToBytes(val)
	if err != nil {
		t.Fatalf("encode error: %v", err)
	}
	exp := Encode([]interface{}{[]interface{}{1, 2, 3}, "4", []interface{}{5}})
	if bytes.Compare(res, exp) != 0 {
		t.Errorf("expected %x, got %x", exp, res)
	}
}