2019-12-06 09:02:43 +00:00
|
|
|
package dbutils
|
|
|
|
|
|
|
|
import (
|
|
|
|
"testing"
|
|
|
|
|
2021-05-20 18:25:53 +00:00
|
|
|
"github.com/ledgerwatch/erigon/common"
|
2019-12-06 09:02:43 +00:00
|
|
|
"github.com/stretchr/testify/assert"
|
|
|
|
)
|
|
|
|
|
2020-05-15 07:52:45 +00:00
|
|
|
func TestPlainParseStoragePrefix(t *testing.T) {
|
|
|
|
expectedAddr := common.HexToAddress("0x5A0b54D5dc17e0AadC383d2db43B0a0D3E029c4c")
|
|
|
|
expectedIncarnation := uint64(999000999)
|
|
|
|
|
2020-06-09 05:52:38 +00:00
|
|
|
prefix := PlainGenerateStoragePrefix(expectedAddr[:], expectedIncarnation)
|
2020-05-15 07:52:45 +00:00
|
|
|
|
|
|
|
addr, incarnation := PlainParseStoragePrefix(prefix)
|
|
|
|
|
|
|
|
assert.Equal(t, expectedAddr, addr, "address should be extracted")
|
|
|
|
assert.Equal(t, expectedIncarnation, incarnation, "incarnation should be extracted")
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestPlainParseCompositeStorageKey(t *testing.T) {
|
|
|
|
expectedAddr := common.HexToAddress("0x5A0b54D5dc17e0AadC383d2db43B0a0D3E029c4c")
|
|
|
|
expectedIncarnation := uint64(999000999)
|
|
|
|
expectedKey := common.HexToHash("0x58833f949125129fb8c6c93d2c6003c5bab7c0b116d695f4ca137b1debf4e472")
|
|
|
|
|
2020-12-08 09:44:29 +00:00
|
|
|
compositeKey := PlainGenerateCompositeStorageKey(expectedAddr.Bytes(), expectedIncarnation, expectedKey.Bytes())
|
2020-05-15 07:52:45 +00:00
|
|
|
|
|
|
|
addr, incarnation, key := PlainParseCompositeStorageKey(compositeKey)
|
|
|
|
|
|
|
|
assert.Equal(t, expectedAddr, addr, "address should be extracted")
|
|
|
|
assert.Equal(t, expectedIncarnation, incarnation, "incarnation should be extracted")
|
|
|
|
assert.Equal(t, expectedKey, key, "key should be extracted")
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestParseStoragePrefix(t *testing.T) {
|
|
|
|
expectedAddrHash, _ := common.HashData(common.HexToAddress("0x5A0b54D5dc17e0AadC383d2db43B0a0D3E029c4c").Bytes())
|
|
|
|
expectedIncarnation := uint64(999000999)
|
|
|
|
|
|
|
|
prefix := GenerateStoragePrefix(expectedAddrHash[:], expectedIncarnation)
|
|
|
|
|
|
|
|
addrHash, incarnation := ParseStoragePrefix(prefix)
|
|
|
|
|
|
|
|
assert.Equal(t, expectedAddrHash, addrHash, "address should be extracted")
|
|
|
|
assert.Equal(t, expectedIncarnation, incarnation, "incarnation should be extracted")
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestParseCompositeStorageKey(t *testing.T) {
|
|
|
|
expectedAddrHash, _ := common.HashData(common.HexToAddress("0x5A0b54D5dc17e0AadC383d2db43B0a0D3E029c4c").Bytes())
|
|
|
|
expectedIncarnation := uint64(999000999)
|
|
|
|
expectedKey := common.HexToHash("0x58833f949125129fb8c6c93d2c6003c5bab7c0b116d695f4ca137b1debf4e472")
|
|
|
|
|
|
|
|
compositeKey := GenerateCompositeStorageKey(expectedAddrHash, expectedIncarnation, expectedKey)
|
|
|
|
|
|
|
|
addrHash, incarnation, key := ParseCompositeStorageKey(compositeKey)
|
|
|
|
|
|
|
|
assert.Equal(t, expectedAddrHash, addrHash, "address should be extracted")
|
|
|
|
assert.Equal(t, expectedIncarnation, incarnation, "incarnation should be extracted")
|
|
|
|
assert.Equal(t, expectedKey, key, "key should be extracted")
|
|
|
|
}
|