Skip to content

Commit

Permalink
Add tests to assure old address length is still supported
Browse files Browse the repository at this point in the history
  • Loading branch information
channa-figure committed Mar 2, 2022
1 parent 3d25094 commit ce034f0
Showing 1 changed file with 36 additions and 1 deletion.
37 changes: 36 additions & 1 deletion x/wasm/types/keys_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,19 +27,54 @@ func TestGetContractByCodeIDSecondaryIndexPrefix(t *testing.T) {
}
}

func TestGetContractCodeHistoryElementPrefix(t *testing.T) {

// test that contract addresses of 20 length are still supported
addr := bytes.Repeat([]byte{4}, 20)
got := GetContractCodeHistoryElementPrefix(addr)
exp := []byte{5, // prefix
4, 4, 4, 4, 4, 4, 4, 4, 4, 4, // address 20 bytes
4, 4, 4, 4, 4, 4, 4, 4, 4, 4,
}
assert.Equal(t, exp, got)

addr = bytes.Repeat([]byte{4}, ContractAddrLen)
got = GetContractCodeHistoryElementPrefix(addr)
exp = []byte{5, // prefix
4, 4, 4, 4, 4, 4, 4, 4, 4, 4, // address 32 bytes
4, 4, 4, 4, 4, 4, 4, 4, 4, 4,
4, 4, 4, 4, 4, 4, 4, 4, 4, 4,
4, 4,
}
assert.Equal(t, exp, got)
}

func TestGetContractByCreatedSecondaryIndexKey(t *testing.T) {
e := ContractCodeHistoryEntry{
CodeID: 1,
Updated: &AbsoluteTxPosition{2 + 1<<(8*7), 3 + 1<<(8*7)},
}
addr := bytes.Repeat([]byte{4}, ContractAddrLen)

// test that contract addresses of 20 length are still supported
addr := bytes.Repeat([]byte{4}, 20)
got := GetContractByCreatedSecondaryIndexKey(addr, e)
exp := []byte{6, // prefix
0, 0, 0, 0, 0, 0, 0, 1, // codeID
1, 0, 0, 0, 0, 0, 0, 2, // height
1, 0, 0, 0, 0, 0, 0, 3, // index
4, 4, 4, 4, 4, 4, 4, 4, 4, 4, // address 32 bytes
4, 4, 4, 4, 4, 4, 4, 4, 4, 4,
}
assert.Equal(t, exp, got)

addr = bytes.Repeat([]byte{4}, ContractAddrLen)
got = GetContractByCreatedSecondaryIndexKey(addr, e)
exp = []byte{6, // prefix
0, 0, 0, 0, 0, 0, 0, 1, // codeID
1, 0, 0, 0, 0, 0, 0, 2, // height
1, 0, 0, 0, 0, 0, 0, 3, // index
4, 4, 4, 4, 4, 4, 4, 4, 4, 4, // address 32 bytes
4, 4, 4, 4, 4, 4, 4, 4, 4, 4,
4, 4, 4, 4, 4, 4, 4, 4, 4, 4,
4, 4,
}
Expand Down

0 comments on commit ce034f0

Please sign in to comment.