good morning!!!!

Skip to content
Snippets Groups Projects
Unverified Commit 677d2f88 authored by Enrique Jose  Avila Asapche's avatar Enrique Jose Avila Asapche Committed by GitHub
Browse files

test tha produces an error for decoding incarnation (#2742)

parent 3f10758f
No related branches found
No related tags found
No related merge requests found
......@@ -528,7 +528,6 @@ func (a *Account) DecodeForStorage(enc []byte) error {
}
func DecodeIncarnationFromStorage(enc []byte) (uint64, error) {
if len(enc) == 0 {
return 0, nil
}
......
......@@ -190,7 +190,7 @@ func isAccountsEqual(t *testing.T, src, dst Account) {
}
}
func testIncarnationForEmptyAccount(t *testing.T) {
func TestIncarnationForEmptyAccount(t *testing.T) {
a := Account{
Initialised: true,
Nonce: 100,
......@@ -202,34 +202,39 @@ func testIncarnationForEmptyAccount(t *testing.T) {
encodedAccount := make([]byte, a.EncodingLengthForStorage())
a.EncodeForStorage(encodedAccount)
var decodedIncarnation uint64
if _, err := DecodeIncarnationFromStorage(encodedAccount); err != nil {
t.Fatal("Can't decode the incarnation", err, encodedAccount)
}
decodedIncarnation, _ = DecodeIncarnationFromStorage(encodedAccount)
decodedIncarnation, err := DecodeIncarnationFromStorage(encodedAccount)
if err != nil {
t.Fatal("Can't decode the incarnation", err, encodedAccount)
}
isIncarnationEqual(t, a.Incarnation, decodedIncarnation)
}
func testEmptyIncarnationForEmptyAccount2(t *testing.T) {
func TestEmptyIncarnationForEmptyAccount2(t *testing.T) {
a := Account{}
encodedAccount := make([]byte, a.EncodingLengthForStorage())
a.EncodeForStorage(encodedAccount)
var decodedIncarnation uint64
if _, err := DecodeIncarnationFromStorage(encodedAccount); err != nil {
t.Fatal("Can't decode the incarnation", err, encodedAccount)
}
decodedIncarnation, _ = DecodeIncarnationFromStorage(encodedAccount)
decodedIncarnation, err := DecodeIncarnationFromStorage(encodedAccount)
if err != nil {
t.Fatal("Can't decode the incarnation", err, encodedAccount)
}
isIncarnationEqual(t, a.Incarnation, decodedIncarnation)
}
func testIncarnationWithNonEmptyAccount(t *testing.T) {
func TestIncarnationWithNonEmptyAccount(t *testing.T) {
a := Account{
Initialised: true,
Nonce: 2,
......@@ -242,18 +247,20 @@ func testIncarnationWithNonEmptyAccount(t *testing.T) {
encodedAccount := make([]byte, a.EncodingLengthForStorage())
a.EncodeForStorage(encodedAccount)
var decodedIncarnation uint64
if _, err := DecodeIncarnationFromStorage(encodedAccount); err != nil {
t.Fatal("Can't decode the incarnation", err, encodedAccount)
}
decodedIncarnation, _ = DecodeIncarnationFromStorage(encodedAccount)
decodedIncarnation, err := DecodeIncarnationFromStorage(encodedAccount)
if err != nil {
t.Fatal("Can't decode the incarnation", err, encodedAccount)
}
isIncarnationEqual(t, a.Incarnation, decodedIncarnation)
}
func testIncarnationWithNoIncarnation(t *testing.T) {
func TestIncarnationWithNoIncarnation(t *testing.T) {
a := Account{
Initialised: true,
Nonce: 2,
......@@ -266,17 +273,29 @@ func testIncarnationWithNoIncarnation(t *testing.T) {
encodedAccount := make([]byte, a.EncodingLengthForStorage())
a.EncodeForStorage(encodedAccount)
var decodedIncarnation uint64
if _, err := DecodeIncarnationFromStorage(encodedAccount); err != nil {
t.Fatal("Can't decode the incarnation", err, encodedAccount)
}
decodedIncarnation, _ = DecodeIncarnationFromStorage(encodedAccount)
decodedIncarnation, err := DecodeIncarnationFromStorage(encodedAccount)
if err != nil {
t.Fatal("Can't decode the incarnation", err, encodedAccount)
}
isIncarnationEqual(t, a.Incarnation, decodedIncarnation)
}
func TestIncarnationWithInvalidEncodedAccount(t *testing.T) {
var failingSlice = []byte{1, 12}
if incarnation, err := DecodeIncarnationFromStorage(failingSlice); err == nil {
t.Fatal("decoded the incarnation", incarnation, failingSlice)
}
}
func isIncarnationEqual(t *testing.T, initialIncarnation uint64, decodedIncarnation uint64) {
if initialIncarnation != decodedIncarnation {
t.Fatal("Can't decode the incarnation", initialIncarnation, decodedIncarnation)
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment