Skip to content

Commit

Permalink
Add test helper function
Browse files Browse the repository at this point in the history
  • Loading branch information
fxamacker committed Nov 25, 2024
1 parent 3a71bf0 commit 7772eb0
Showing 1 changed file with 64 additions and 50 deletions.
114 changes: 64 additions & 50 deletions runtime/storage_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8120,7 +8120,7 @@ func TestGetDomainStorageMapRegisterReadsForNewAccount(t *testing.T) {
},
},
expectedReadsSet: map[string]struct{}{
string(address[:]) + "|" + common.StorageDomainPathStorage.Identifier(): {},
concatRegisterAddressAndDomain(address, common.StorageDomainPathStorage): {},
},
},
{
Expand All @@ -8141,7 +8141,7 @@ func TestGetDomainStorageMapRegisterReadsForNewAccount(t *testing.T) {
// domain storage map is created and cached in the first GetDomainStorageMap().
},
expectedReadsSet: map[string]struct{}{
string(address[:]) + "|" + common.StorageDomainPathStorage.Identifier(): {},
concatRegisterAddressAndDomain(address, common.StorageDomainPathStorage): {},
},
},
// Test cases with storageFormatV2Enabled = true
Expand Down Expand Up @@ -8211,16 +8211,16 @@ func TestGetDomainStorageMapRegisterReadsForNewAccount(t *testing.T) {
},
},
expectedReadsSet: map[string]struct{}{
string(address[:]) + "|" + AccountStorageKey: {},
string(address[:]) + "|" + common.StorageDomainPathStorage.Identifier(): {},
string(address[:]) + "|" + common.StorageDomainPathPrivate.Identifier(): {},
string(address[:]) + "|" + common.StorageDomainPathPublic.Identifier(): {},
string(address[:]) + "|" + common.StorageDomainContract.Identifier(): {},
string(address[:]) + "|" + common.StorageDomainInbox.Identifier(): {},
string(address[:]) + "|" + common.StorageDomainCapabilityController.Identifier(): {},
string(address[:]) + "|" + common.StorageDomainCapabilityControllerTag.Identifier(): {},
string(address[:]) + "|" + common.StorageDomainPathCapability.Identifier(): {},
string(address[:]) + "|" + common.StorageDomainAccountCapability.Identifier(): {},
concatRegisterAddressAndKey(address, []byte(AccountStorageKey)): {},
concatRegisterAddressAndDomain(address, common.StorageDomainPathStorage): {},
concatRegisterAddressAndDomain(address, common.StorageDomainPathPrivate): {},
concatRegisterAddressAndDomain(address, common.StorageDomainPathPublic): {},
concatRegisterAddressAndDomain(address, common.StorageDomainContract): {},
concatRegisterAddressAndDomain(address, common.StorageDomainInbox): {},
concatRegisterAddressAndDomain(address, common.StorageDomainCapabilityController): {},
concatRegisterAddressAndDomain(address, common.StorageDomainCapabilityControllerTag): {},
concatRegisterAddressAndDomain(address, common.StorageDomainPathCapability): {},
concatRegisterAddressAndDomain(address, common.StorageDomainAccountCapability): {},
},
},
{
Expand Down Expand Up @@ -8283,16 +8283,16 @@ func TestGetDomainStorageMapRegisterReadsForNewAccount(t *testing.T) {
// domain storage map is created and cached in the first GetDomainStorageMap().
},
expectedReadsSet: map[string]struct{}{
string(address[:]) + "|" + AccountStorageKey: {},
string(address[:]) + "|" + common.StorageDomainPathStorage.Identifier(): {},
string(address[:]) + "|" + common.StorageDomainPathPrivate.Identifier(): {},
string(address[:]) + "|" + common.StorageDomainPathPublic.Identifier(): {},
string(address[:]) + "|" + common.StorageDomainContract.Identifier(): {},
string(address[:]) + "|" + common.StorageDomainInbox.Identifier(): {},
string(address[:]) + "|" + common.StorageDomainCapabilityController.Identifier(): {},
string(address[:]) + "|" + common.StorageDomainCapabilityControllerTag.Identifier(): {},
string(address[:]) + "|" + common.StorageDomainPathCapability.Identifier(): {},
string(address[:]) + "|" + common.StorageDomainAccountCapability.Identifier(): {},
concatRegisterAddressAndKey(address, []byte(AccountStorageKey)): {},
concatRegisterAddressAndDomain(address, common.StorageDomainPathStorage): {},
concatRegisterAddressAndDomain(address, common.StorageDomainPathPrivate): {},
concatRegisterAddressAndDomain(address, common.StorageDomainPathPublic): {},
concatRegisterAddressAndDomain(address, common.StorageDomainContract): {},
concatRegisterAddressAndDomain(address, common.StorageDomainInbox): {},
concatRegisterAddressAndDomain(address, common.StorageDomainCapabilityController): {},
concatRegisterAddressAndDomain(address, common.StorageDomainCapabilityControllerTag): {},
concatRegisterAddressAndDomain(address, common.StorageDomainPathCapability): {},
concatRegisterAddressAndDomain(address, common.StorageDomainAccountCapability): {},
},
},
}
Expand Down Expand Up @@ -8437,7 +8437,7 @@ func TestGetDomainStorageMapRegisterReadsForV1Account(t *testing.T) {
},
},
expectedReadsSet: map[string]struct{}{
string(address[:]) + "|" + common.StorageDomainPathStorage.Identifier(): {},
concatRegisterAddressAndDomain(address, common.StorageDomainPathStorage): {},
},
},
{
Expand All @@ -8460,7 +8460,7 @@ func TestGetDomainStorageMapRegisterReadsForV1Account(t *testing.T) {
// GetDomainStorageMap(0).
},
expectedReadsSet: map[string]struct{}{
string(address[:]) + "|" + common.StorageDomainPathStorage.Identifier(): {},
concatRegisterAddressAndDomain(address, common.StorageDomainPathStorage): {},
},
},
{
Expand Down Expand Up @@ -8488,8 +8488,8 @@ func TestGetDomainStorageMapRegisterReadsForV1Account(t *testing.T) {
// GetDomainStorageMap(0).
},
expectedReadsSet: map[string]struct{}{
string(address[:]) + "|" + common.StorageDomainPathStorage.Identifier(): {},
string(address[:]) + "|" + string([]byte{'$', 0, 0, 0, 0, 0, 0, 0, 1}): {},
concatRegisterAddressAndDomain(address, common.StorageDomainPathStorage): {},
concatRegisterAddressAndKey(address, []byte{'$', 0, 0, 0, 0, 0, 0, 0, 1}): {},
},
},
{
Expand Down Expand Up @@ -8517,8 +8517,8 @@ func TestGetDomainStorageMapRegisterReadsForV1Account(t *testing.T) {
// GetDomainStorageMap(0).
},
expectedReadsSet: map[string]struct{}{
string(address[:]) + "|" + common.StorageDomainPathStorage.Identifier(): {},
string(address[:]) + "|" + string([]byte{'$', 0, 0, 0, 0, 0, 0, 0, 1}): {},
concatRegisterAddressAndDomain(address, common.StorageDomainPathStorage): {},
concatRegisterAddressAndKey(address, []byte{'$', 0, 0, 0, 0, 0, 0, 0, 1}): {},
},
},
// Test cases with storageFormatV2Enabled = true
Expand Down Expand Up @@ -8562,10 +8562,10 @@ func TestGetDomainStorageMapRegisterReadsForV1Account(t *testing.T) {
},
},
expectedReadsSet: map[string]struct{}{
string(address[:]) + "|" + AccountStorageKey: {},
string(address[:]) + "|" + common.StorageDomainPathStorage.Identifier(): {},
string(address[:]) + "|" + common.StorageDomainPathPrivate.Identifier(): {},
string(address[:]) + "|" + common.StorageDomainPathPublic.Identifier(): {},
concatRegisterAddressAndKey(address, []byte(AccountStorageKey)): {},
concatRegisterAddressAndDomain(address, common.StorageDomainPathStorage): {},
concatRegisterAddressAndDomain(address, common.StorageDomainPathPrivate): {},
concatRegisterAddressAndDomain(address, common.StorageDomainPathPublic): {},
},
},
{
Expand Down Expand Up @@ -8606,10 +8606,10 @@ func TestGetDomainStorageMapRegisterReadsForV1Account(t *testing.T) {
// GetDomainStorageMap().
},
expectedReadsSet: map[string]struct{}{
string(address[:]) + "|" + AccountStorageKey: {},
string(address[:]) + "|" + common.StorageDomainPathStorage.Identifier(): {},
string(address[:]) + "|" + common.StorageDomainPathPrivate.Identifier(): {},
string(address[:]) + "|" + common.StorageDomainPathPublic.Identifier(): {},
concatRegisterAddressAndKey(address, []byte(AccountStorageKey)): {},
concatRegisterAddressAndDomain(address, common.StorageDomainPathStorage): {},
concatRegisterAddressAndDomain(address, common.StorageDomainPathPrivate): {},
concatRegisterAddressAndDomain(address, common.StorageDomainPathPublic): {},
},
},
{
Expand Down Expand Up @@ -8647,9 +8647,9 @@ func TestGetDomainStorageMapRegisterReadsForV1Account(t *testing.T) {
// GetDomainStorageMap().
},
expectedReadsSet: map[string]struct{}{
string(address[:]) + "|" + AccountStorageKey: {},
string(address[:]) + "|" + common.StorageDomainPathStorage.Identifier(): {},
string(address[:]) + "|" + string([]byte{'$', 0, 0, 0, 0, 0, 0, 0, 1}): {},
concatRegisterAddressAndKey(address, []byte(AccountStorageKey)): {},
concatRegisterAddressAndDomain(address, common.StorageDomainPathStorage): {},
concatRegisterAddressAndKey(address, []byte{'$', 0, 0, 0, 0, 0, 0, 0, 1}): {},
},
},
{
Expand Down Expand Up @@ -8687,9 +8687,9 @@ func TestGetDomainStorageMapRegisterReadsForV1Account(t *testing.T) {
// GetDomainStorageMap().
},
expectedReadsSet: map[string]struct{}{
string(address[:]) + "|" + AccountStorageKey: {},
string(address[:]) + "|" + common.StorageDomainPathStorage.Identifier(): {},
string(address[:]) + "|" + string([]byte{'$', 0, 0, 0, 0, 0, 0, 0, 1}): {},
concatRegisterAddressAndKey(address, []byte(AccountStorageKey)): {},
concatRegisterAddressAndDomain(address, common.StorageDomainPathStorage): {},
concatRegisterAddressAndKey(address, []byte{'$', 0, 0, 0, 0, 0, 0, 0, 1}): {},
},
},
}
Expand Down Expand Up @@ -8859,8 +8859,8 @@ func TestGetDomainStorageMapRegisterReadsForV2Account(t *testing.T) {
// GetDomainStorageMap().
},
expectedReadsSet: map[string]struct{}{
string(address[:]) + "|" + AccountStorageKey: {},
string(address[:]) + "|" + string([]byte{'$', 0, 0, 0, 0, 0, 0, 0, 1}): {},
concatRegisterAddressAndKey(address, []byte(AccountStorageKey)): {},
concatRegisterAddressAndKey(address, []byte{'$', 0, 0, 0, 0, 0, 0, 0, 1}): {},
},
},
{
Expand Down Expand Up @@ -8892,8 +8892,8 @@ func TestGetDomainStorageMapRegisterReadsForV2Account(t *testing.T) {
// GetDomainStorageMap().
},
expectedReadsSet: map[string]struct{}{
string(address[:]) + "|" + AccountStorageKey: {},
string(address[:]) + "|" + string([]byte{'$', 0, 0, 0, 0, 0, 0, 0, 1}): {},
concatRegisterAddressAndKey(address, []byte(AccountStorageKey)): {},
concatRegisterAddressAndKey(address, []byte{'$', 0, 0, 0, 0, 0, 0, 0, 1}): {},
},
},
{
Expand Down Expand Up @@ -8925,8 +8925,8 @@ func TestGetDomainStorageMapRegisterReadsForV2Account(t *testing.T) {
// GetDomainStorageMap().
},
expectedReadsSet: map[string]struct{}{
string(address[:]) + "|" + AccountStorageKey: {},
string(address[:]) + "|" + string([]byte{'$', 0, 0, 0, 0, 0, 0, 0, 1}): {},
concatRegisterAddressAndKey(address, []byte(AccountStorageKey)): {},
concatRegisterAddressAndKey(address, []byte{'$', 0, 0, 0, 0, 0, 0, 0, 1}): {},
},
},
{
Expand Down Expand Up @@ -8958,8 +8958,8 @@ func TestGetDomainStorageMapRegisterReadsForV2Account(t *testing.T) {
// GetDomainStorageMap().
},
expectedReadsSet: map[string]struct{}{
string(address[:]) + "|" + AccountStorageKey: {},
string(address[:]) + "|" + string([]byte{'$', 0, 0, 0, 0, 0, 0, 0, 1}): {},
concatRegisterAddressAndKey(address, []byte(AccountStorageKey)): {},
concatRegisterAddressAndKey(address, []byte{'$', 0, 0, 0, 0, 0, 0, 0, 1}): {},
},
},
}
Expand Down Expand Up @@ -9175,3 +9175,17 @@ func newSlabStorage(ledger atree.Ledger) *atree.PersistentSlabStorage {
decodeTypeInfo,
)
}

func concatRegisterAddressAndKey(
address common.Address,
key []byte,
) string {
return string(address[:]) + "|" + string(key)
}

func concatRegisterAddressAndDomain(
address common.Address,
domain common.StorageDomain,
) string {
return string(address[:]) + "|" + domain.Identifier()
}

0 comments on commit 7772eb0

Please sign in to comment.