Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test(encoding): adds a fuzz test for da path encoding #733

Merged
merged 3 commits into from
Apr 28, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

### Bug Fixes

* **da:** fixed da path seperator and encoding issue ([#731](https://github.com/dymensionxyz/dymint/issues/731)) ([3a3b219](https://github.com/dymensionxyz/dymint/commit/3a3b21932750fee7eaaa9c186f78e36e3e597746))
* **p2p:** validate block before applying and not before caching in p2p gossiping ([#723](https://github.com/dymensionxyz/dymint/issues/723)) ([98371b5](https://github.com/dymensionxyz/dymint/commit/98371b5220613e70f3274fab5593e02ba532f7db))
* **produce loop:** handle unauthenticated error in settlement layer ([#726](https://github.com/dymensionxyz/dymint/issues/726)) ([33e78d1](https://github.com/dymensionxyz/dymint/commit/33e78d116b5f14b91b8b3bda2b6cbfee9040e2d3))

Expand Down
30 changes: 30 additions & 0 deletions da/da_test.go
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
package da_test

import (
"bytes"
cryptoRand "crypto/rand"
"encoding/json"
"math/rand" //#gosec
"strings"
"testing"
"time"

Expand Down Expand Up @@ -250,3 +252,31 @@ func getRandomBytes(n int) []byte {
_, _ = cryptoRand.Read(data)
return data
}

func FuzzDASubmitMetaData(f *testing.F) {
f.Fuzz(func(t *testing.T, client string, height uint64, index, length int, commitment, namespace, root []byte) {
if client == "" || strings.Contains(client, da.PathSeparator) || len(commitment) == 0 || len(namespace) == 0 || len(root) == 0 {
t.Skip()
}
data := da.DASubmitMetaData{
Client: da.Client(client),
Height: height,
Index: index,
Length: length,
Commitment: commitment,
Namespace: namespace,
Root: root,
}

path := data.ToPath()
got, err := data.FromPath(path)
require.NoError(t, err)
require.Equal(t, data.Client, got.Client)
require.Equal(t, data.Height, got.Height)
require.Equal(t, data.Index, got.Index)
require.Equal(t, data.Length, got.Length)
require.True(t, bytes.Equal(data.Commitment, got.Commitment))
require.True(t, bytes.Equal(data.Namespace, got.Namespace))
require.True(t, bytes.Equal(data.Root, got.Root))
})
}