Skip to content

Commit

Permalink
Some test framework additions
Browse files Browse the repository at this point in the history
Signed-off-by: Leonard Lyubich <ctulhurider@gmail.com>
  • Loading branch information
cthulhu-rider committed Feb 22, 2023
1 parent bdc5064 commit 75edfcb
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 2 deletions.
2 changes: 1 addition & 1 deletion balance/migration_test.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package balance
package balance_test

import (
"testing"
Expand Down
30 changes: 29 additions & 1 deletion tests/migration/model.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package migration

import (
"bytes"
"testing"
)

Expand Down Expand Up @@ -91,6 +92,33 @@ func PersistedItemsWithKeyLength(ln int) ItemGroupModel {
}
}

// PersistedItemsWithPrefix describes persistence of the storage items with
// specified key prefix.
func PersistedItemsWithPrefix(prefix string) ItemGroupModel {
return ItemGroupModel{
keyPattern: func(key []byte) bool {
return bytes.HasPrefix(key, []byte(prefix))
},
modifier: persistedModifier,
}
}

// ReplacedItemsWithKeyLength describes replacement of the storage items with
// fixed-length keys.
func ReplacedItemsWithKeyLength(ln int, changeKey func(prevKey []byte) []byte) ItemGroupModel {
return ItemGroupModel{
keyPattern: func(key []byte) bool {
return len(key) == ln
},
modifier: func(prev kv) kv {
return kv{
k: changeKey(prev.k),
v: prev.v,
}
},
}
}

// apply applies the UpdateModel to pre-update storage items of some contract
// and returns list of expected post-update items. Fails if any of items is not
// covered by the UpdateModel.
Expand All @@ -103,7 +131,7 @@ nextItem:
continue nextItem
}
}
tb.Fatalf("unexpected storage item '%s', did you forget to forget to include it in the model?")
tb.Fatalf("unexpected storage item '%s', did you forget to forget to include it in the model?", in[i].k)
}
return
}

0 comments on commit 75edfcb

Please sign in to comment.