Msg/Create

A basket can be created:

  • when the basket name is unique
  • when the required basket fee is not set and no fee is provided
  • when the basket fee denom matches the required basket fee denom
  • when the basket fee amount is greater than or equal to the required basket fee amount
  • when the admin balance is greater than or equal to the required basket fee amount
  • when the basket includes a credit type that exists
  • when the basket criteria includes credit classes that exist
  • when the basket criteria includes credit classes that match the credit type
  • when the basket criteria includes optional date criteria
  • the user token balance is updated and only the minimum fee is taken
  • the basket denom is formatted with a prefix based on credit type precision
  • the response includes the basket denom

The basket name must be unique

Background

Given a credit type.

basket name is unique

When alice attempts to create a basket with name "NCT"

Then expect no error.

basket name is not unique

Given a basket with name "NCT"

When alice attempts to create a basket with name "NCT"

Then expect the error "basket with name NCT already exists: unique key violation".

The basket fee is not required if the required basket fee is not set

Background

Given a credit type.

basket fee provided and required basket fee not set

Given alice has a token balance "20regen"

When alice attempts to create a basket with fee "20regen"

Then expect no error.

basket fee not provided and required basket fee not set

When alice attempts to create a basket with no fee

Then expect no error.

The basket fee must match the required basket fee denom

Background

Given a credit type

And alice has a token balance "20regen".

basket fee matches required basket fee denom

Given required basket fee "20regen"

When alice attempts to create a basket with fee "20regen"

Then expect no error.

basket fee does not match required basket fee denom

Given required basket fee "20regen"

When alice attempts to create a basket with fee "20atom"

Then expect the error "fee must be 20regen, got 20atom: insufficient fee".

basket fee not provided and required basket fee set

Given required basket fee "20regen"

When alice attempts to create a basket with no fee

Then expect the error "fee cannot be empty: must be 20regen: insufficient fee".

The basket fee must be greater than or equal to the required basket fee

Background

Given a credit type

And alice has a token balance "20regen".

basket fee is greater than or equal to required basket fee amount

Given required basket fee "20regen"

When alice attempts to create a basket with fee "[basket-fee]"

Then expect no error.

Examples

descriptionbasket-fee
greater than30regen
equal to20regen

basket fee is less than required basket fee amount

Given required basket fee "20regen"

When alice attempts to create a basket with fee "10regen"

Then expect the error "fee must be 20regen, got 10regen: insufficient fee".

The admin must have a balance greater than or equal to basket fee amount

Background

Given a credit type

And required basket fee "20regen".

admin balance is greater than or equal to required basket fee amount

Given alice has a token balance "[token-balance]"

When alice attempts to create a basket with fee "20regen"

Then expect no error.

Examples

descriptiontoken-balance
greater than30regen
equal to20regen

admin balance is less than required basket fee amount

Given alice has a token balance "10regen"

When alice attempts to create a basket with fee "20regen"

Then expect the error "insufficient balance 10 for bank denom regen: insufficient funds".

The basket must include a credit type that exists

Background

Given a credit type with abbreviation "C".

basket credit type exists

When alice attempts to create a basket with credit type "C"

Then expect no error.

basket credit type does not exist

When alice attempts to create a basket with credit type "F"

Then expect the error "could not get credit type with abbreviation F: not found: invalid request".

The basket criteria must include a credit class that exists

Background

Given a credit type with abbreviation "C".

basket criteria credit class exists

Given a credit class with id "C01"

When alice attempts to create a basket with allowed class "C01"

Then expect no error.

basket criteria credit class does not exist

When alice attempts to create a basket with allowed class "C01"

Then expect the error "could not get credit class C01: not found: invalid request".

The basket criteria must include a credit class that matches the credit type

Background

Given a credit type with abbreviation "C".

basket criteria credit class matches credit type

Given a credit class with id "C01"

When alice attempts to create a basket with credit type "C" and allowed class "C01"

Then expect no error.

basket criteria credit class does not match credit type

Given a credit class with id "BIO01"

When alice attempts to create a basket with credit type "C" and allowed class "BIO01"

Then expect the error "basket specified credit type C, but class BIO01 is of type BIO: invalid request".

The basket criteria may include optional start date criteria

Background

Given a credit type.

basket criteria minimum start date

When alice attempts to create a basket with minimum start date "2020-01-01"

Then expect minimum start date "2020-01-01".

basket criteria start date window

When alice attempts to create a basket with start date window "43800h"

Then expect start date window "43800h".

basket criteria years in the past

When alice attempts to create a basket with years in the past "10"

Then expect years in the past "10".

The user token balance is updated and only the minimum fee is taken

Background

Given a credit type

And required basket fee "20regen"

And alice has a token balance "40regen".

user token balance is updated

When alice attempts to create a basket with fee "[basket-fee]"

Then expect alice token balance "[token-balance]".

Examples

descriptionbasket-feetoken-balance
greater than40regen20regen
equal to20regen20regen

The basket denom is formatted with a prefix based on credit type precision

basket denom is formatted using credit type precision

Given a credit type with abbreviation "C" and precision "[precision]"

When alice attempts to create a basket with name "NCT" and credit type "C"

Then expect the response

{
  "basket_denom": "<basket-denom>"
}

Examples

descriptionprecisionbasket-denom
no prefix0eco.C.NCT
d (deci)1eco.dC.NCT
c (centi)2eco.cC.NCT
m (milli)3eco.mC.NCT
u (micro)6eco.uC.NCT
n (nano)9eco.nC.NCT
p (pico)12eco.pC.NCT
f (femto)15eco.fC.NCT
a (atto)18eco.aC.NCT
z (zepto)21eco.zC.NCT
y (yocto)24eco.yC.NCT

The message response includes basket denom

message response includes the basket denom

Given a credit type with abbreviation "C" and precision "6"

When alice attempts to create a basket with name "NCT"

Then expect the response

{
  "basket_denom": "eco.uC.NCT"
}

Event is emitted

EventCreate is emitted

Given a credit type with abbreviation "C" and precision "6"

And alice's address "regen1depk54cuajgkzea6zpgkq36tnjwdzv4ak663u6"

When alice attempts to create a basket with name "NCT"

Then expect event with properties

{
  "curator": "regen1depk54cuajgkzea6zpgkq36tnjwdzv4ak663u6",
  "basket_denom": "eco.uC.NCT"
}