Skip to content

Commit

Permalink
Merge branch 'noot/kusama-block-4939774' of github.com:ChainSafe/goss…
Browse files Browse the repository at this point in the history
…amer into noot/kusama-block-4939774
  • Loading branch information
noot committed Mar 16, 2021
2 parents c8efd49 + 6163b3b commit e829c5f
Show file tree
Hide file tree
Showing 5 changed files with 59 additions and 9 deletions.
26 changes: 26 additions & 0 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,32 @@ jobs:

- name: Run build
run: make build

publish-code-coverage:
runs-on: ubuntu-latest
steps:
- uses: actions/setup-go@v1
with:
go-version: ${{ matrix.go-version }}
- uses: actions/checkout@v2

- name: Cache go modules
uses: actions/cache@v1
with:
path: ~/go/pkg/mod
key: ${{ runner.os }}-go-${{ hashFiles('go.sum') }}
restore-keys: ${{ runner.os }}-go-

- name: Generate coverage report
run: |
go test ./... -short -coverprofile=coverage.out -covermode=atomic -timeout=20m
- uses: codecov/codecov-action@v1
with:
token: "89982880-a53b-4a3a-9bdd-3dc9c78bd190"
files: ./coverage.out
flags: unit-tests
name: coverage
verbose: true

docker-build-n-push:
runs-on: ubuntu-latest
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -61,9 +61,9 @@ jobs:
with:
token: "89982880-a53b-4a3a-9bdd-3dc9c78bd190"
files: ./coverage.out
flags: unittests
flags: unit-tests
name: coverage
verbose: trues
verbose: true

docker-stable-tests:
runs-on: ubuntu-latest
Expand Down
10 changes: 3 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,8 @@
<img alt="go report card" src="https://goreportcard.com/badge/github.com/ChainSafe/gossamer?style=for-the-badge" height="20" />
</a>
</div>
<div align="center">
<a href="https://codeclimate.com/github/ChainSafe/gossamer/badges">
<img alt="maintainability" src="https://img.shields.io/codeclimate/maintainability/ChainSafe/gossamer?style=for-the-badge" height="20" />
</a>
<a href="https://codeclimate.com/github/ChainSafe/gossamer/test_coverage">
<img alt="Test Coverage" src="https://img.shields.io/codeclimate/coverage/ChainSafe/gossamer?style=for-the-badge" height="20" />
<a href="https://app.codecov.io/gh/ChainSafe/gossamer">
<img alt="Test Coverage" src="https://img.shields.io/codecov/c/github/ChainSafe/gossamer?flag=unittests&style=for-the-badge&token=89982880-a53b-4a3a-9bdd-3dc9c78bd190" height="20" />
</a>
<a href="https://discord.gg/zy8eRF7FG2">
<img alt="Discord" src="https://img.shields.io/discord/593655374469660673.svg?style=for-the-badge&label=Discord&logo=discord" height="20"/>
Expand All @@ -29,7 +25,7 @@
<img alt="Gossamer Blog" src="https://img.shields.io/badge/Medium-grey?style=for-the-badge&logo=medium" height="20" />
</a>
<a href="https://medium.com/chainsafe-systems/tagged/polkadot">
<img alt="Gossamer Blog" src="https://img.shields.io/twitter/follow/chainsafeth?color=blue&label=follow&logo=twitter&style=for-the-badge" height="20"/>
<img alt="Twitter" src="https://img.shields.io/twitter/follow/chainsafeth?color=blue&label=follow&logo=twitter&style=for-the-badge" height="20"/>
</a>
</div>
<br />
Expand Down
8 changes: 8 additions & 0 deletions lib/trie/trie.go
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,10 @@ func (t *Trie) nextKey(curr node, prefix, key []byte) []byte {
fullKey := append(prefix, c.key...)
var cmp int
if len(key) < len(fullKey) {
if bytes.Compare(key, fullKey[:len(key)]) == 1 { // arg key is greater than full, return nil
return nil
}

// the key is lexicographically less than the current node key. return first key available
cmp = 1
} else {
Expand Down Expand Up @@ -209,6 +213,10 @@ func (t *Trie) nextKey(curr node, prefix, key []byte) []byte {
fullKey := append(prefix, c.key...)
var cmp int
if len(key) < len(fullKey) {
if bytes.Compare(key, fullKey[:len(key)]) == 1 { // arg key is greater than full, return nil
return nil
}

// the key is lexicographically less than the current node key. return first key available
cmp = 1
} else {
Expand Down
20 changes: 20 additions & 0 deletions lib/trie/trie_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -739,6 +739,26 @@ func TestNextKey_Again(t *testing.T) {
}
}

func TestNextKey_HostAPI(t *testing.T) {
trie := NewEmptyTrie()

var testCases = []string{
":code",
":heappages",
}

for _, tc := range testCases {
trie.Put([]byte(tc), []byte(tc))
}

nextCases := []string{"Opti", "Option"}

for _, tc := range nextCases {
next := trie.NextKey([]byte(tc))
require.Nil(t, next)
}
}

func TestClearPrefix(t *testing.T) {
tests := []Test{
{key: []byte{0x01, 0x35}, value: []byte("spaghetti"), op: PUT},
Expand Down

0 comments on commit e829c5f

Please sign in to comment.