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

fix(x/ecocredit): fix core message validation and update tests #1233

Merged
merged 7 commits into from
Jul 7, 2022
Merged
Show file tree
Hide file tree
Changes from 6 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
130 changes: 130 additions & 0 deletions x/ecocredit/core/features/msg_cancel.feature
Original file line number Diff line number Diff line change
@@ -0,0 +1,130 @@
Feature: MsgCancel

Scenario: a valid message
Given the message
"""
{
"owner": "regen1depk54cuajgkzea6zpgkq36tnjwdzv4ak663u6",
"credits": [
{
"batch_denom": "C01-001-20200101-20210101-001",
"amount": "100"
}
],
"reason": "transferring credits to another registry"
}
"""
When the message is validated
Then expect no error

Scenario: a valid message with multiple credits
Given the message
"""
{
"owner": "regen1depk54cuajgkzea6zpgkq36tnjwdzv4ak663u6",
"credits": [
{
"batch_denom": "C01-001-20200101-20210101-001",
"amount": "100"
},
{
"batch_denom": "C01-001-20200101-20210101-002",
"amount": "100"
}
],
"reason": "transferring credits to another registry"
}
"""
When the message is validated
Then expect no error

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

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

Scenario: an error is returned if credits is empty
Given the message
"""
{
"owner": "regen1depk54cuajgkzea6zpgkq36tnjwdzv4ak663u6"
}
"""
When the message is validated
Then expect the error "credits cannot be empty: invalid request"

Scenario: an error is returned if credits batch denom is empty
Given the message
"""
{
"owner": "regen1depk54cuajgkzea6zpgkq36tnjwdzv4ak663u6",
"credits": [
{}
]
}
"""
When the message is validated
Then expect the error "credits[0]: batch denom cannot be empty: invalid request"

Scenario: an error is returned if credits amount is empty
Given the message
"""
{
"owner": "regen1depk54cuajgkzea6zpgkq36tnjwdzv4ak663u6",
"credits": [
{
"batch_denom": "C01-001-20200101-20210101-001"
}
]
}
"""
When the message is validated
Then expect the error "credits[0]: amount cannot be empty: invalid request"

# Note: additional validation for credits covered in types_credits.feature

Scenario: an error is returned if reason is empty
Given the message
"""
{
"owner": "regen1depk54cuajgkzea6zpgkq36tnjwdzv4ak663u6",
"credits": [
{
"batch_denom": "C01-001-20200101-20210101-001",
"amount": "100"
}
]
}
"""
When the message is validated
Then expect the error "reason cannot be empty: invalid request"

Scenario: an error is returned if reason exceeds 512 characters
Given the message
"""
{
"owner": "regen1depk54cuajgkzea6zpgkq36tnjwdzv4ak663u6",
"credits": [
{
"batch_denom": "C01-001-20200101-20210101-001",
"amount": "100"
}
]
}
"""
And a reason with length "513"
When the message is validated
Then expect the error "reason: max length 512: limit exceeded"
130 changes: 130 additions & 0 deletions x/ecocredit/core/features/msg_retire.feature
Original file line number Diff line number Diff line change
@@ -0,0 +1,130 @@
Feature: MsgRetire

Scenario: a valid message
Given the message
"""
{
"owner": "regen1depk54cuajgkzea6zpgkq36tnjwdzv4ak663u6",
"credits": [
{
"batch_denom": "C01-001-20200101-20210101-001",
"amount": "100"
}
],
"jurisdiction": "US-WA"
}
"""
When the message is validated
Then expect no error

Scenario: a valid message with multiple credits
Given the message
"""
{
"owner": "regen1depk54cuajgkzea6zpgkq36tnjwdzv4ak663u6",
"credits": [
{
"batch_denom": "C01-001-20200101-20210101-001",
"amount": "100"
},
{
"batch_denom": "C01-001-20200101-20210101-002",
"amount": "100"
}
],
"jurisdiction": "US-WA"
}
"""
When the message is validated
Then expect no error

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

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

Scenario: an error is returned if credits is empty
Given the message
"""
{
"owner": "regen1depk54cuajgkzea6zpgkq36tnjwdzv4ak663u6"
}
"""
When the message is validated
Then expect the error "credits cannot be empty: invalid request"

Scenario: an error is returned if credits batch denom is empty
Given the message
"""
{
"owner": "regen1depk54cuajgkzea6zpgkq36tnjwdzv4ak663u6",
"credits": [
{}
]
}
"""
When the message is validated
Then expect the error "credits[0]: batch denom cannot be empty: invalid request"

Scenario: an error is returned if credits amount is empty
Given the message
"""
{
"owner": "regen1depk54cuajgkzea6zpgkq36tnjwdzv4ak663u6",
"credits": [
{
"batch_denom": "C01-001-20200101-20210101-001"
}
]
}
"""
When the message is validated
Then expect the error "credits[0]: amount cannot be empty: invalid request"

# Note: additional validation for credits covered in types_credits.feature

Scenario: an error is returned if jurisdiction is empty
Given the message
"""
{
"owner": "regen1depk54cuajgkzea6zpgkq36tnjwdzv4ak663u6",
"credits": [
{
"batch_denom": "C01-001-20200101-20210101-001",
"amount": "100"
}
]
}
"""
When the message is validated
Then expect the error "jurisdiction cannot be empty: invalid request"

Scenario: an error is returned if jurisdiction is not formatted
Given the message
"""
{
"owner": "regen1depk54cuajgkzea6zpgkq36tnjwdzv4ak663u6",
"credits": [
{
"batch_denom": "C01-001-20200101-20210101-001",
"amount": "100"
}
],
"jurisdiction": "foo"
}
"""
When the message is validated
Then expect the error "invalid jurisdiction: foo, expected format <country-code>[-<region-code>[ <postal-code>]]: parse error"
51 changes: 51 additions & 0 deletions x/ecocredit/core/features/msg_seal_batch.feature
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
Feature: MsgSealBatch

Scenario: a valid message
Given the message
"""
{
"issuer": "regen1depk54cuajgkzea6zpgkq36tnjwdzv4ak663u6",
"batch_denom": "C01-001-20200101-20210101-001"
}
"""
When the message is validated
Then expect no error

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

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

Scenario: an error is returned if batch denom is empty
Given the message
"""
{
"issuer": "regen1depk54cuajgkzea6zpgkq36tnjwdzv4ak663u6"
}
"""
When the message is validated
Then expect the error "batch denom cannot be empty: invalid request"

Scenario: an error is returned if batch denom is not formatted
Given the message
"""
{
"issuer": "regen1depk54cuajgkzea6zpgkq36tnjwdzv4ak663u6",
"batch_denom": "foo"
}
"""
When the message is validated
Then expect the error "invalid batch denom: expected format A00-000-00000000-00000000-000: parse error"
Loading