Msg/CreateClass
A credit class can be created:
- message validations
- when the credit type exists
- when the allowlist is enabled and the admin is an approved credit class creator
- when the required class fee is not set and no fee is provided
- when the credit class fee denom matches the required class fee denom
- when the credit class fee amount is greater than or equal to the required class fee amount
- when the admin balance is greater than or equal to an allowed basket fee amount
- the admin balance is updated and only the required fee is taken
- the class sequence is updated
- the class issuers are added
- the class properties are added
- the response includes the class id
Message validations
a valid message
Given the message
{
"admin": "regen1depk54cuajgkzea6zpgkq36tnjwdzv4ak663u6",
"issuers": [
"regen1depk54cuajgkzea6zpgkq36tnjwdzv4ak663u6"
],
"metadata": "regen:13toVgf5aZqSVSeJQv562xkkeoe3rr3bJWa29PHVKVf77VAkVMcDvVd.rdf",
"credit_type_abbrev": "C",
"fee": {
"denom": "uregen",
"amount": "20000000"
}
}
When the message is validated
Then expect no error.
a valid message with multiple issuers
Given the message
{
"admin": "regen1depk54cuajgkzea6zpgkq36tnjwdzv4ak663u6",
"issuers": [
"regen1depk54cuajgkzea6zpgkq36tnjwdzv4ak663u6",
"regen1tnh2q55v8wyygtt9srz5safamzdengsnlm0yy4"
],
"metadata": "regen:13toVgf5aZqSVSeJQv562xkkeoe3rr3bJWa29PHVKVf77VAkVMcDvVd.rdf",
"credit_type_abbrev": "C",
"fee": {
"denom": "uregen",
"amount": "20000000"
}
}
When the message is validated
Then expect no error.
a valid message without fee
Given the message
{
"admin": "regen1depk54cuajgkzea6zpgkq36tnjwdzv4ak663u6",
"issuers": [
"regen1depk54cuajgkzea6zpgkq36tnjwdzv4ak663u6"
],
"metadata": "regen:13toVgf5aZqSVSeJQv562xkkeoe3rr3bJWa29PHVKVf77VAkVMcDvVd.rdf",
"credit_type_abbrev": "C"
}
When the message is validated
Then expect no error.
an error is returned if issuers is empty
Given the message
{
"admin": "regen1depk54cuajgkzea6zpgkq36tnjwdzv4ak663u6"
}
When the message is validated
Then expect the error "issuers cannot be empty: invalid request".
an error is returned if issuer is a duplicate
Given the message
{
"admin": "regen1depk54cuajgkzea6zpgkq36tnjwdzv4ak663u6",
"issuers": [
"regen1depk54cuajgkzea6zpgkq36tnjwdzv4ak663u6",
"regen1depk54cuajgkzea6zpgkq36tnjwdzv4ak663u6"
]
}
When the message is validated
Then expect the error "issuers[1]: duplicate address regen1depk54cuajgkzea6zpgkq36tnjwdzv4ak663u6: invalid request".
an error is returned if metadata is exceeds 256 characters
Given the message
{
"admin": "regen1depk54cuajgkzea6zpgkq36tnjwdzv4ak663u6",
"issuers": [
"regen1depk54cuajgkzea6zpgkq36tnjwdzv4ak663u6"
]
}
And metadata with length "257"
When the message is validated
Then expect the error "metadata: max length 256: limit exceeded".
an error is returned if credit type abbreviation is empty
Given the message
{
"admin": "regen1depk54cuajgkzea6zpgkq36tnjwdzv4ak663u6",
"issuers": [
"regen1depk54cuajgkzea6zpgkq36tnjwdzv4ak663u6"
],
"metadata": "regen:13toVgf5aZqSVSeJQv562xkkeoe3rr3bJWa29PHVKVf77VAkVMcDvVd.rdf"
}
When the message is validated
Then expect the error "credit type abbrev: empty string is not allowed: parse error: invalid request".
an error is returned if credit type abbreviation is not formatted
Given the message
{
"admin": "regen1depk54cuajgkzea6zpgkq36tnjwdzv4ak663u6",
"issuers": [
"regen1depk54cuajgkzea6zpgkq36tnjwdzv4ak663u6"
],
"metadata": "regen:13toVgf5aZqSVSeJQv562xkkeoe3rr3bJWa29PHVKVf77VAkVMcDvVd.rdf",
"credit_type_abbrev": "foobar"
}
When the message is validated
Then expect the error "credit type abbrev: must be 1-3 uppercase alphabetic characters: parse error: invalid request".
an error is returned if fee denom is empty
Given the message
{
"admin": "regen1depk54cuajgkzea6zpgkq36tnjwdzv4ak663u6",
"issuers": [
"regen1depk54cuajgkzea6zpgkq36tnjwdzv4ak663u6"
],
"metadata": "regen:13toVgf5aZqSVSeJQv562xkkeoe3rr3bJWa29PHVKVf77VAkVMcDvVd.rdf",
"credit_type_abbrev": "C",
"fee": {}
}
When the message is validated
Then expect the error "fee denom cannot be empty: invalid request".
an error is returned if fee denom is not a valid bank denom
Given the message
{
"admin": "regen1depk54cuajgkzea6zpgkq36tnjwdzv4ak663u6",
"issuers": [
"regen1depk54cuajgkzea6zpgkq36tnjwdzv4ak663u6"
],
"metadata": "regen:13toVgf5aZqSVSeJQv562xkkeoe3rr3bJWa29PHVKVf77VAkVMcDvVd.rdf",
"credit_type_abbrev": "C",
"fee": {
"denom": "1"
}
}
When the message is validated
Then expect the error "invalid denom: 1: invalid request".
an error is returned if fee amount is empty
Given the message
{
"admin": "regen1depk54cuajgkzea6zpgkq36tnjwdzv4ak663u6",
"issuers": [
"regen1depk54cuajgkzea6zpgkq36tnjwdzv4ak663u6"
],
"metadata": "regen:13toVgf5aZqSVSeJQv562xkkeoe3rr3bJWa29PHVKVf77VAkVMcDvVd.rdf",
"credit_type_abbrev": "C",
"fee": {
"denom": "uregen"
}
}
When the message is validated
Then expect the error "fee amount cannot be empty: invalid request".
an error is returned if fee amount is not positive
Given the message
{
"admin": "regen1depk54cuajgkzea6zpgkq36tnjwdzv4ak663u6",
"issuers": [
"regen1depk54cuajgkzea6zpgkq36tnjwdzv4ak663u6"
],
"metadata": "regen:13toVgf5aZqSVSeJQv562xkkeoe3rr3bJWa29PHVKVf77VAkVMcDvVd.rdf",
"credit_type_abbrev": "C",
"fee": {
"denom": "uregen",
"amount": "-20000000"
}
}
When the message is validated
Then expect the error "fee amount must be positive: insufficient fee".
The credit type must exist
credit type exists
Given a credit type with abbreviation "A"
When alice attempts to create a credit class with credit type "A"
Then expect no error.
credit type exists
Given a credit type with abbreviation "A"
When alice attempts to create a credit class with credit type "B"
Then expect the error "could not get credit type with abbreviation B: not found: invalid request".
The admin must be an approved credit class creator if the allowlist is enabled
Background
Given a credit type.
allowlist disabled and admin is an approved creator
Given allowlist enabled "false"
And alice is an approved credit class creator
When alice attempts to create a credit class
Then expect no error.
allowlist disabled and admin is not an approved creator
Given allowlist enabled "false"
When alice attempts to create a credit class
Then expect no error.
allowlist enabled and admin is an approved creator
Given allowlist enabled "true"
And alice is an approved credit class creator
When alice attempts to create a credit class
Then expect no error.
allowlist enabled and admin is not an approved creator
Given allowlist enabled "true"
When alice attempts to create a credit class
Then expect error contains "is not allowed to create credit classes: unauthorized".
The credit class fee is not required if the required class fee is not set
Background
Given a credit type.
credit class fee provided and required class fee not set
Given alice has a token balance "20regen"
When alice attempts to create a credit class with fee "20regen"
Then expect no error.
credit class fee not provided and required class fee not set
When alice attempts to create a credit class
Then expect no error.
The credit class fee must match a credit class fee denom
Background
Given a credit type
And alice has a token balance "20regen".
credit class fee matches required class fee denom
Given required class fee "20regen"
When alice attempts to create a credit class with fee "20regen"
Then expect no error.
credit class fee does not match required class fee denom
Given required class fee "20regen"
When alice attempts to create a credit class with fee "20atom"
Then expect the error "fee must be 20regen, got 20atom: insufficient fee".
credit class fee not provided and required class fee set
Given required class fee "20regen"
When alice attempts to create a credit class
Then expect the error "fee cannot be empty: must be 20regen: insufficient fee".
The credit class fee must be greater than or equal to a credit class fee
Background
Given a credit type
And alice has a token balance "20regen".
credit class fee is greater than or equal to required class fee
Given required class fee "20regen"
When alice attempts to create a credit class with fee "[class-fee]"
Then expect no error.
Examples
| description | class-fee |
|---|---|
| greater than | 30regen |
| equal to | 20regen |
credit class fee is less than required class fee
Given required class fee "20regen"
When alice attempts to create a credit class with fee "10regen"
Then expect the error "fee must be 20regen, got 10regen: insufficient fee".
The user must have a balance greater than or equal to the credit class fee amount
Background
Given a credit type
And required class fee "20regen".
admin balance is greater than or equal to credit class fee amount
Given alice has a token balance "[token-balance]"
When alice attempts to create a credit class with fee "20regen"
Then expect no error.
Examples
| description | token-balance |
|---|---|
| greater than | 30regen |
| equal to | 20regen |
admin balance is less than credit class fee amount
Given alice has a token balance "10regen"
When alice attempts to create a credit class with fee "20regen"
Then expect the error "insufficient balance 10 for bank denom regen: insufficient funds".
The class sequence is updated
Background
Given a credit type with abbreviation "A".
the class sequence is updated
Given a class sequence with credit type "A" and next sequence "1"
When alice attempts to create a credit class with credit type "A"
Then expect class sequence with credit type "A" and next sequence "2".
the class sequence is not updated
Given a class sequence with credit type "A" and next sequence "1"
When alice attempts to create a credit class with credit type "B"
Then expect class sequence with credit type "A" and next sequence "1".
The class issuers are added
Background
Given a credit type.
the class issuers are added
When alice attempts to create a credit class with issuers
[
"regen1depk54cuajgkzea6zpgkq36tnjwdzv4ak663u6",
"regen1tnh2q55v8wyygtt9srz5safamzdengsnlm0yy4"
]
Then expect class issuers
[
"regen1depk54cuajgkzea6zpgkq36tnjwdzv4ak663u6",
"regen1tnh2q55v8wyygtt9srz5safamzdengsnlm0yy4"
]
The class properties are added
Background
Given a credit type with abbreviation "A".
the class properties are added
When alice attempts to create a credit class with properties
{
"credit_type_abbrev": "A",
"metadata": "regen:13toVfvC2YxrrfSXWB5h2BGHiXZURsKxWUz72uDRDSPMCrYPguGUXSC.rdf"
}
Then expect class properties
{
"id": "A01",
"credit_type_abbrev": "A",
"metadata": "regen:13toVfvC2YxrrfSXWB5h2BGHiXZURsKxWUz72uDRDSPMCrYPguGUXSC.rdf"
}
The response includes the class id
Background
Given a credit type with abbreviation "A".
the response includes the class id
When alice attempts to create a credit class with credit type "A"
Then expect the response
{
"class_id": "A01"
}
Event is emitted
Background
Given a credit type with abbreviation "A".
EventCreateClass is emitted
When alice attempts to create a credit class with credit type "A"
Then expect event with properties
{
"class_id": "A01"
}