Skip to content

Commit

Permalink
test(x/data): add acceptance tests (#994)
Browse files Browse the repository at this point in the history
* test(x/data): add acceptance tests

* fix attest and mockgen

* messge validation example

* messge validation example

* messge validation example

* update server tests

* define resolver

* update server tests

* update message tests

* cleanup

* resolver url error

* resolver url error

* update message validation

* update message validation

* update content hash validation

* update server method tests

* use define resolver

* update format for steps with variables

* use jsonpb and base64 hash

* update content hash references

* add content hash test case

* add rules and update steps

* add rules and no error

* remove rules and refine steps

* content hash no error

* parse date and get data id

* more specific scenarios

* minor cleanup

* valid scenario first

* remove background text

* separate message files
  • Loading branch information
ryanchristo authored Apr 16, 2022
1 parent e7f79fb commit 93bd343
Show file tree
Hide file tree
Showing 39 changed files with 1,537 additions and 825 deletions.
16 changes: 8 additions & 8 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -248,11 +248,10 @@ github.com/cpuguy83/go-md2man/v2 v2.0.1 h1:r/myEWzV9lfsM1tFLgDyu0atFtJ1fXn261LKY
github.com/cpuguy83/go-md2man/v2 v2.0.1/go.mod h1:tgQtvFlXSQOSOSIRvRPT7W67SCa46tRHOmNcaadrF8o=
github.com/creack/pty v1.1.7/go.mod h1:lj5s0c3V2DBrqTV7llrYr5NG6My20zk30Fl46Y7DoTY=
github.com/creack/pty v1.1.9/go.mod h1:oKZEueFk5CKHvIhNR5MUki03XCEU+Q6VDXinZuGJ33E=
github.com/cucumber/gherkin-go/v19 v19.0.3 h1:mMSKu1077ffLbTJULUfM5HPokgeBcIGboyeNUof1MdE=
github.com/cucumber/gherkin-go/v19 v19.0.3/go.mod h1:jY/NP6jUtRSArQQJ5h1FXOUgk5fZK24qtE7vKi776Vw=
github.com/cucumber/messages-go/v16 v16.0.0/go.mod h1:EJcyR5Mm5ZuDsKJnT2N9KRnBK30BGjtYotDKpwQ0v6g=
github.com/cucumber/messages-go/v16 v16.0.1 h1:fvkpwsLgnIm0qugftrw2YwNlio+ABe2Iu94Ap8GMYIY=
github.com/cucumber/messages-go/v16 v16.0.1/go.mod h1:EJcyR5Mm5ZuDsKJnT2N9KRnBK30BGjtYotDKpwQ0v6g=
github.com/cucumber/common/gherkin/go/v22 v22.0.0 h1:4K8NqptbvdOrjL9DEea6HFjSpbdT9+Q5kgLpmmsHYl0=
github.com/cucumber/common/gherkin/go/v22 v22.0.0/go.mod h1:3mJT10B2GGn3MvVPd3FwR7m2u4tLhSRhWUqJU4KN4Fg=
github.com/cucumber/common/messages/go/v17 v17.1.1 h1:RNqopvIFyLWnKv0LfATh34SWBhXeoFTJnSrgm9cT/Ts=
github.com/cucumber/common/messages/go/v17 v17.1.1/go.mod h1:bpGxb57tDE385Rb2EohgUadLkAbhoC4IyCFi89u/JQI=
github.com/cyphar/filepath-securejoin v0.2.2/go.mod h1:FpkQEhXnPnOthhzymB7CGsFk2G9VLXONKD9G7QGMM+4=
github.com/danieljoos/wincred v1.0.2 h1:zf4bhty2iLuwgjgpraD2E9UbvO+fe54XXGJbOwe23fU=
github.com/danieljoos/wincred v1.0.2/go.mod h1:SnuYRW9lp1oJrZX/dXJqr0cPK5gYXqx3EJbmjhLdK9U=
Expand Down Expand Up @@ -370,8 +369,9 @@ github.com/gobwas/ws v1.0.2/go.mod h1:szmBTxLgaFppYjEmNtny/v3w89xOydFnnZMcgRRu/E
github.com/godbus/dbus v0.0.0-20190726142602-4481cbc300e2 h1:ZpnhV/YsD2/4cESfV5+Hoeu/iUR3ruzNvZ+yQfO03a0=
github.com/godbus/dbus v0.0.0-20190726142602-4481cbc300e2/go.mod h1:bBOAhwG1umN6/6ZUMtDFBMQR8jRg9O75tm9K00oMsK4=
github.com/godbus/dbus/v5 v5.0.4/go.mod h1:xhWf0FNVPg57R7Z0UbKHbJfkEywrmjJnf7w5xrFpKfA=
github.com/gofrs/uuid v4.0.0+incompatible h1:1SD/1F5pU8p29ybwgQSwpQk+mwdRrXCYuPhW6m+TnJw=
github.com/gofrs/uuid v4.0.0+incompatible/go.mod h1:b2aQJv3Z4Fp6yNu3cdSllBxTCLRxnplIgP/c0N/04lM=
github.com/gofrs/uuid v4.2.0+incompatible h1:yyYWMnhkhrKwwr8gAOcOCYxOOscHgDS9yZgBrnJfGa0=
github.com/gofrs/uuid v4.2.0+incompatible/go.mod h1:b2aQJv3Z4Fp6yNu3cdSllBxTCLRxnplIgP/c0N/04lM=
github.com/gogo/gateway v1.1.0 h1:u0SuhL9+Il+UbjM9VIE3ntfRujKbvVpFvNB4HbjeVQ0=
github.com/gogo/gateway v1.1.0/go.mod h1:S7rR8FRQyG3QFESeSv4l2WnsyzlCLG0CzBbUUo/mbic=
github.com/golang-jwt/jwt/v4 v4.0.0/go.mod h1:/xlHOz8bRuivTWchD4jCa+NbatV+wEUSzwAxVc6locg=
Expand Down Expand Up @@ -846,8 +846,8 @@ github.com/regen-network/cosmos-proto v0.3.1 h1:rV7iM4SSFAagvy8RiyhiACbWEGotmqzy
github.com/regen-network/cosmos-proto v0.3.1/go.mod h1:jO0sVX6a1B36nmE8C9xBFXpNwWejXC7QqCOnH3O0+YM=
github.com/regen-network/cosmos-sdk v0.45.0-regen-1 h1:NCXi5HqcIg/dLW6n+niFJ5AmudgWxoODldrzW8fCWrg=
github.com/regen-network/cosmos-sdk v0.45.0-regen-1/go.mod h1:3u9K1P67wuSfLNPtKF/E4y01/hb50xhqGYEtobkT56I=
github.com/regen-network/gocuke v0.6.0 h1:33I/Omwnhav+1gRYJnb82AcYuPXz6/yhk3y//oEnxGw=
github.com/regen-network/gocuke v0.6.0/go.mod h1:+i/R+pDBMLx1M7rL3fV7FC18gzyVTdGu3rNLUSOzHIo=
github.com/regen-network/gocuke v0.6.2 h1:pHviZ0kKAq2U2hN2q3smKNxct6hS0mGByFMHGnWA97M=
github.com/regen-network/gocuke v0.6.2/go.mod h1:zYaqIHZobHyd0xOrHGPQjbhGJsuZ1oElx150u2o1xuk=
github.com/regen-network/protobuf v1.3.3-alpha.regen.1 h1:OHEc+q5iIAXpqiqFKeLpu5NwTIkVXUs48vFMwzqpqY4=
github.com/regen-network/protobuf v1.3.3-alpha.regen.1/go.mod h1:2DjTFR1HhMQhiWC5sZ4OhQ3+NtdbZ6oBDKQwq5Ou+FI=
github.com/regen-network/regen-ledger/orm v1.0.0-beta1 h1:io3MMmqpIy3YCdkGmcsP+xAaq3JZi1/OAWk3ut+Th9s=
Expand Down
2 changes: 1 addition & 1 deletion types/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ require (
github.com/gogo/protobuf v1.3.3
github.com/golang/mock v1.6.0
github.com/grpc-ecosystem/grpc-gateway v1.16.0
github.com/pkg/errors v0.9.1
github.com/regen-network/regen-ledger/api v0.8.0
github.com/spf13/cobra v1.2.1
github.com/stretchr/testify v1.7.1
Expand Down Expand Up @@ -90,7 +91,6 @@ require (
github.com/nxadm/tail v1.4.8 // indirect
github.com/pelletier/go-toml v1.9.4 // indirect
github.com/petermattis/goid v0.0.0-20180202154549-b0b1615b78e5 // indirect
github.com/pkg/errors v0.9.1 // indirect
github.com/pmezard/go-difflib v1.0.0 // indirect
github.com/prometheus/client_golang v1.11.0 // indirect
github.com/prometheus/client_model v0.2.0 // indirect
Expand Down
47 changes: 47 additions & 0 deletions x/data/features/msg_anchor.feature
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
Feature: MsgAnchor

Scenario: a valid message
Given the message
"""
{
"sender": "cosmos1depk54cuajgkzea6zpgkq36tnjwdzv4afc3d27",
"content_hash": {
"raw": {
"hash": "AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA=",
"digest_algorithm": 1
}
}
}
"""
When the message is validated
Then expect no error

Scenario: an error is returned if sender is empty
Given the message
"""
{}
"""
When the message is validated
Then expect the error "empty address string is not allowed: invalid address"

Scenario: an error is returned if sender is not a bech32 address
Given the message
"""
{
"sender": "foo"
}
"""
When the message is validated
Then expect the error "decoding bech32 failed: invalid bech32 string length 3: invalid address"

Scenario: an error is returned if content hash is empty
Given the message
"""
{
"sender": "cosmos1depk54cuajgkzea6zpgkq36tnjwdzv4afc3d27"
}
"""
When the message is validated
Then expect the error "content hash cannot be empty: invalid request"

# Note: see ./types_content_hash.feature for content hash validation
48 changes: 48 additions & 0 deletions x/data/features/msg_attest.feature
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
Feature: MsgAttest

Scenario: a valid message
Given the message
"""
{
"attestor": "cosmos1depk54cuajgkzea6zpgkq36tnjwdzv4afc3d27",
"content_hashes": [
{
"hash": "AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA=",
"digest_algorithm": 1,
"canonicalization_algorithm": 1
}
]
}
"""
When the message is validated
Then expect no error

Scenario: an error is returned if attestor is empty
Given the message
"""
{}
"""
When the message is validated
Then expect the error "empty address string is not allowed: invalid address"

Scenario: an error is returned if attestor is not a bech32 address
Given the message
"""
{
"attestor": "foo"
}
"""
When the message is validated
Then expect the error "decoding bech32 failed: invalid bech32 string length 3: invalid address"

Scenario: an error is returned if content hashes is empty
Given the message
"""
{
"attestor": "cosmos1depk54cuajgkzea6zpgkq36tnjwdzv4afc3d27"
}
"""
When the message is validated
Then expect the error "content hashes cannot be empty: invalid request"

# Note: see ./types_content_hash.feature for content hash validation
51 changes: 51 additions & 0 deletions x/data/features/msg_define_resolver.feature
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
Feature: MsgDefineResolver

Scenario: a valid message
Given the message
"""
{
"manager": "cosmos1depk54cuajgkzea6zpgkq36tnjwdzv4afc3d27",
"resolver_url": "https://foo.bar"
}
"""
When the message is validated
Then expect no error

Scenario: an error is returned if manager is empty
Given the message
"""
{}
"""
When the message is validated
Then expect the error "empty address string is not allowed: invalid address"

Scenario: an error is returned if manager is not a bech32 address
Given the message
"""
{
"manager": "foo"
}
"""
When the message is validated
Then expect the error "decoding bech32 failed: invalid bech32 string length 3: invalid address"

Scenario: an error is returned if resolver url is empty
Given the message
"""
{
"manager": "cosmos1depk54cuajgkzea6zpgkq36tnjwdzv4afc3d27"
}
"""
When the message is validated
Then expect the error "invalid resolver url: invalid request"

Scenario: an error is returned if resolver url is missing a protocol
Given the message
"""
{
"manager": "cosmos1depk54cuajgkzea6zpgkq36tnjwdzv4afc3d27",
"resolver_url": "foo.bar"
}
"""
When the message is validated
Then expect the error "invalid resolver url: invalid request"
61 changes: 61 additions & 0 deletions x/data/features/msg_register_resolver.feature
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
Feature: MsgRegisterResolver

Scenario: a valid message
Given the message
"""
{
"manager": "cosmos1depk54cuajgkzea6zpgkq36tnjwdzv4afc3d27",
"resolver_id": 1,
"content_hashes": [
{
"raw": {
"hash": "AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA=",
"digest_algorithm": 1
}
}
]
}
"""
When the message is validated
Then expect no error

Scenario: an error is returned if manager is empty
Given the message
"""
{}
"""
When the message is validated
Then expect the error "empty address string is not allowed: invalid address"

Scenario: an error is returned if manager is not a bech32 address
Given the message
"""
{
"manager": "foo"
}
"""
When the message is validated
Then expect the error "decoding bech32 failed: invalid bech32 string length 3: invalid address"

Scenario: an error is returned if resolver id is empty
Given the message
"""
{
"manager": "cosmos1depk54cuajgkzea6zpgkq36tnjwdzv4afc3d27"
}
"""
When the message is validated
Then expect the error "resolver id cannot be empty: invalid request"

Scenario: an error is returned if content hashes is empty
Given the message
"""
{
"manager": "cosmos1depk54cuajgkzea6zpgkq36tnjwdzv4afc3d27",
"resolver_id": 1
}
"""
When the message is validated
Then expect the error "content hashes cannot be empty: invalid request"

# Note: see ./types_content_hash.feature for content hash validation
Loading

0 comments on commit 93bd343

Please sign in to comment.