Skip to content

Commit

Permalink
test fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
aaronc committed Mar 19, 2024
1 parent 6e60592 commit a5aa435
Show file tree
Hide file tree
Showing 12 changed files with 44 additions and 31 deletions.
3 changes: 2 additions & 1 deletion x/ecocredit/base/keeper/features/msg_create_batch.feature
Original file line number Diff line number Diff line change
Expand Up @@ -359,7 +359,8 @@ Feature: Msg/CreateBatch
"metadata": "regen:13toVfvC2YxrrfSXWB5h2BGHiXZURsKxWUz72uDRDSPMCrYPguGUXSC.rdf",
"start_date": "2020-01-01T00:00:00Z",
"end_date": "2021-01-01T00:00:00Z",
"open": true
"open": true,
"class_key": 1
}
"""

Expand Down
13 changes: 0 additions & 13 deletions x/ecocredit/base/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -158,19 +158,6 @@ func ValidateJurisdiction(jurisdiction string) error {
return nil
}

// GetClassIDFromLegacyProjectID extracts the credit class ID from a legacy project ID.
func GetClassIDFromLegacyProjectID(projectID string) string {
var s strings.Builder
for _, r := range projectID {
if r != '-' {
s.WriteRune(r)
continue
}
break
}
return s.String()
}

// GetClassIDFromBatchDenom returns the credit class ID in a batch denom.
func GetClassIDFromBatchDenom(denom string) string {
var s strings.Builder
Expand Down
15 changes: 10 additions & 5 deletions x/ecocredit/basket/keeper/msg_put_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -222,7 +222,7 @@ func (s *putSuite) ACreditBatchWithDenom(a string) {
classID := base.GetClassIDFromBatchDenom(a)
creditTypeAbbrev := base.GetCreditTypeAbbrevFromClassID(classID)

_, err := s.baseStore.ClassTable().InsertReturningID(s.ctx, &baseapi.Class{
clsKey, err := s.baseStore.ClassTable().InsertReturningID(s.ctx, &baseapi.Class{
Id: classID,
CreditTypeAbbrev: creditTypeAbbrev,
})
Expand All @@ -233,6 +233,7 @@ func (s *putSuite) ACreditBatchWithDenom(a string) {

err = s.baseStore.BatchTable().Insert(s.ctx, &baseapi.Batch{
ProjectKey: projectKey,
ClassKey: clsKey,
Denom: s.batchDenom,
})
require.NoError(s.t, err)
Expand All @@ -254,7 +255,7 @@ func (s *putSuite) AliceOwnsCredits() {
classID := base.GetClassIDFromBatchDenom(s.batchDenom)
creditTypeAbbrev := base.GetCreditTypeAbbrevFromClassID(classID)

_, err := s.baseStore.ClassTable().InsertReturningID(s.ctx, &baseapi.Class{
clsKey, err := s.baseStore.ClassTable().InsertReturningID(s.ctx, &baseapi.Class{
Id: classID,
CreditTypeAbbrev: creditTypeAbbrev,
})
Expand All @@ -265,6 +266,7 @@ func (s *putSuite) AliceOwnsCredits() {

batchKey, err := s.baseStore.BatchTable().InsertReturningID(s.ctx, &baseapi.Batch{
ProjectKey: projectKey,
ClassKey: clsKey,
Denom: s.batchDenom,
})
require.NoError(s.t, err)
Expand All @@ -281,7 +283,7 @@ func (s *putSuite) AliceOwnsCreditAmount(a string) {
classID := base.GetClassIDFromBatchDenom(s.batchDenom)
creditTypeAbbrev := base.GetCreditTypeAbbrevFromClassID(classID)

_, err := s.baseStore.ClassTable().InsertReturningID(s.ctx, &baseapi.Class{
clsKey, err := s.baseStore.ClassTable().InsertReturningID(s.ctx, &baseapi.Class{
Id: classID,
CreditTypeAbbrev: creditTypeAbbrev,
})
Expand All @@ -292,6 +294,7 @@ func (s *putSuite) AliceOwnsCreditAmount(a string) {

batchKey, err := s.baseStore.BatchTable().InsertReturningID(s.ctx, &baseapi.Batch{
ProjectKey: projectKey,
ClassKey: clsKey,
Denom: s.batchDenom,
})
require.NoError(s.t, err)
Expand All @@ -308,7 +311,7 @@ func (s *putSuite) AliceOwnsCreditsFromCreditBatch(a string) {
classID := base.GetClassIDFromBatchDenom(a)
creditTypeAbbrev := base.GetCreditTypeAbbrevFromClassID(classID)

_, err := s.baseStore.ClassTable().InsertReturningID(s.ctx, &baseapi.Class{
clsKey, err := s.baseStore.ClassTable().InsertReturningID(s.ctx, &baseapi.Class{
Id: classID,
CreditTypeAbbrev: creditTypeAbbrev,
})
Expand All @@ -319,6 +322,7 @@ func (s *putSuite) AliceOwnsCreditsFromCreditBatch(a string) {

batchKey, err := s.baseStore.BatchTable().InsertReturningID(s.ctx, &baseapi.Batch{
ProjectKey: projectKey,
ClassKey: clsKey,
Denom: a,
})
require.NoError(s.t, err)
Expand All @@ -335,7 +339,7 @@ func (s *putSuite) AliceOwnsCreditsWithStartDate(a string) {
startDate, err := regentypes.ParseDate("start-date", a)
require.NoError(s.t, err)

_, err = s.baseStore.ClassTable().InsertReturningID(s.ctx, &baseapi.Class{
clsKey, err := s.baseStore.ClassTable().InsertReturningID(s.ctx, &baseapi.Class{
Id: s.classID,
CreditTypeAbbrev: s.creditTypeAbbrev,
})
Expand All @@ -346,6 +350,7 @@ func (s *putSuite) AliceOwnsCreditsWithStartDate(a string) {

batchKey, err := s.baseStore.BatchTable().InsertReturningID(s.ctx, &baseapi.Batch{
ProjectKey: pKey,
ClassKey: clsKey,
Denom: s.batchDenom,
StartDate: timestamppb.New(startDate),
})
Expand Down
3 changes: 2 additions & 1 deletion x/ecocredit/basket/keeper/msg_take_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -418,7 +418,7 @@ func (s *takeSuite) addBasketClassAndBalance(basketID uint64, creditAmount strin
classID := base.GetClassIDFromBatchDenom(s.batchDenom)
creditTypeAbbrev := base.GetCreditTypeAbbrevFromClassID(classID)

_, err = s.baseStore.ClassTable().InsertReturningID(s.ctx, &baseapi.Class{
clsKey, err := s.baseStore.ClassTable().InsertReturningID(s.ctx, &baseapi.Class{
Id: classID,
CreditTypeAbbrev: creditTypeAbbrev,
})
Expand All @@ -429,6 +429,7 @@ func (s *takeSuite) addBasketClassAndBalance(basketID uint64, creditAmount strin

batchKey, err := s.baseStore.BatchTable().InsertReturningID(s.ctx, &baseapi.Batch{
ProjectKey: projectKey,
ClassKey: clsKey,
Denom: s.batchDenom,
})
require.NoError(s.t, err)
Expand Down
6 changes: 6 additions & 0 deletions x/ecocredit/genesis/genesis_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -250,6 +250,7 @@ func TestGenesisValidate(t *testing.T) {
bKey, err := ss.BatchTable().InsertReturningID(ctx, &baseapi.Batch{
Issuer: addr1,
ProjectKey: pKey,
ClassKey: cKey,
Denom: denom,
StartDate: &timestamppb.Timestamp{Seconds: 100},
EndDate: &timestamppb.Timestamp{Seconds: 101},
Expand Down Expand Up @@ -298,6 +299,7 @@ func TestGenesisValidate(t *testing.T) {
bKey, err := ss.BatchTable().InsertReturningID(ctx, &baseapi.Batch{
Issuer: addr1,
ProjectKey: pKey,
ClassKey: cKey,
Denom: denom,
StartDate: &timestamppb.Timestamp{Seconds: 100},
EndDate: &timestamppb.Timestamp{Seconds: 101},
Expand Down Expand Up @@ -350,6 +352,7 @@ func TestGenesisValidate(t *testing.T) {
bKey, err := ss.BatchTable().InsertReturningID(ctx, &baseapi.Batch{
Issuer: addr1,
ProjectKey: pKey,
ClassKey: cKey,
Denom: "C01-001-00000000-00000000-001",
StartDate: &timestamppb.Timestamp{Seconds: 100},
EndDate: &timestamppb.Timestamp{Seconds: 101},
Expand Down Expand Up @@ -433,6 +436,7 @@ func TestGenesisValidate(t *testing.T) {
bKey, err := ss.BatchTable().InsertReturningID(ctx, &baseapi.Batch{
Issuer: addr1,
ProjectKey: pKey,
ClassKey: cKey,
Denom: "C01-001-00000000-00000000-001",
StartDate: &timestamppb.Timestamp{Seconds: 100},
EndDate: &timestamppb.Timestamp{Seconds: 101},
Expand All @@ -442,6 +446,7 @@ func TestGenesisValidate(t *testing.T) {
bKeyBIO, err := ss.BatchTable().InsertReturningID(ctx, &baseapi.Batch{
Issuer: addr1,
ProjectKey: pKeyBIO,
ClassKey: cKeyBIO,
Denom: "BIO01-001-00000000-00000000-001",
StartDate: &timestamppb.Timestamp{Seconds: 100},
EndDate: &timestamppb.Timestamp{Seconds: 101},
Expand All @@ -451,6 +456,7 @@ func TestGenesisValidate(t *testing.T) {
bKey2, err := ss.BatchTable().InsertReturningID(ctx, &baseapi.Batch{
Issuer: addr1,
ProjectKey: pKey,
ClassKey: cKey,
Denom: "C01-001-00000000-00000000-002",
StartDate: &timestamppb.Timestamp{Seconds: 100},
EndDate: &timestamppb.Timestamp{Seconds: 101},
Expand Down
8 changes: 6 additions & 2 deletions x/ecocredit/marketplace/keeper/keeper_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ type baseSuite struct {
bankKeeper *mocks.MockBankKeeper
storeKey *storetypes.KVStoreKey
sdkCtx sdk.Context
classId uint64
}

func setupBase(t gocuke.TestingT, numAddresses int) *baseSuite {
Expand Down Expand Up @@ -116,14 +117,17 @@ func (s *baseSuite) testSellSetup(batchDenom, bankDenom, displayDenom, classID s
Precision: 6,
}))

assert.NilError(s.t, s.baseStore.ClassTable().Insert(s.ctx, &baseapi.Class{
var err error
s.classId, err = s.baseStore.ClassTable().InsertReturningID(s.ctx, &baseapi.Class{
Id: classID,
Admin: s.addrs[0],
Metadata: "",
CreditTypeAbbrev: creditType.Abbreviation,
}))
})
assert.NilError(s.t, err)
assert.NilError(s.t, s.baseStore.BatchTable().Insert(s.ctx, &baseapi.Batch{
ProjectKey: 1,
ClassKey: s.classId,
Denom: batchDenom,
Metadata: "",
StartDate: start,
Expand Down
5 changes: 3 additions & 2 deletions x/ecocredit/marketplace/keeper/msg_buy_direct_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -629,14 +629,15 @@ func (s *buyDirectSuite) createSellOrders(count int) {
totalQuantity = t.String()
}

err := s.baseStore.ClassTable().Insert(s.ctx, &baseapi.Class{
clsId, err := s.baseStore.ClassTable().InsertReturningID(s.ctx, &baseapi.Class{
Id: s.classID,
CreditTypeAbbrev: s.creditTypeAbbrev,
})
require.NoError(s.t, err)

batchKey, err := s.baseStore.BatchTable().InsertReturningID(s.ctx, &baseapi.Batch{
Denom: s.batchDenom,
Denom: s.batchDenom,
ClassKey: clsId,
})
require.NoError(s.t, err)

Expand Down
5 changes: 3 additions & 2 deletions x/ecocredit/marketplace/keeper/msg_cancel_sell_order_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -151,14 +151,15 @@ func (s *cancelSellOrder) ExpectEventWithProperties(a gocuke.DocString) {
}

func (s *cancelSellOrder) sellOrderSetup() {
err := s.baseStore.ClassTable().Insert(s.ctx, &baseapi.Class{
clsId, err := s.baseStore.ClassTable().InsertReturningID(s.ctx, &baseapi.Class{
Id: s.classID,
CreditTypeAbbrev: s.creditTypeAbbrev,
})
require.NoError(s.t, err)

batchKey, err := s.baseStore.BatchTable().InsertReturningID(s.ctx, &baseapi.Batch{
Denom: s.batchDenom,
Denom: s.batchDenom,
ClassKey: clsId,
})
require.NoError(s.t, err)

Expand Down
6 changes: 4 additions & 2 deletions x/ecocredit/marketplace/keeper/msg_sell_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ func (s *sellSuite) ACreditBatchWithBatchDenom(a string) {
classID := base.GetClassIDFromBatchDenom(a)
creditTypeAbbrev := base.GetCreditTypeAbbrevFromClassID(classID)

_, err := s.baseStore.ClassTable().InsertReturningID(s.ctx, &baseapi.Class{
clsKey, err := s.baseStore.ClassTable().InsertReturningID(s.ctx, &baseapi.Class{
Id: classID,
CreditTypeAbbrev: creditTypeAbbrev,
})
Expand All @@ -121,6 +121,7 @@ func (s *sellSuite) ACreditBatchWithBatchDenom(a string) {

err = s.baseStore.BatchTable().Insert(s.ctx, &baseapi.Batch{
ProjectKey: projectKey,
ClassKey: clsKey,
Denom: a,
})
require.NoError(s.t, err)
Expand Down Expand Up @@ -419,7 +420,7 @@ func (s *sellSuite) ExpectEventWithProperties(a gocuke.DocString) {
}

func (s *sellSuite) aliceTradableBatchBalance() {
_, err := s.baseStore.ClassTable().InsertReturningID(s.ctx, &baseapi.Class{
clsKey, err := s.baseStore.ClassTable().InsertReturningID(s.ctx, &baseapi.Class{
Id: s.classID,
CreditTypeAbbrev: s.creditTypeAbbrev,
})
Expand All @@ -430,6 +431,7 @@ func (s *sellSuite) aliceTradableBatchBalance() {

batchKey, err := s.baseStore.BatchTable().InsertReturningID(s.ctx, &baseapi.Batch{
ProjectKey: projectKey,
ClassKey: clsKey,
Denom: s.batchDenom,
})
require.NoError(s.t, err)
Expand Down
8 changes: 5 additions & 3 deletions x/ecocredit/marketplace/keeper/msg_update_sell_orders_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -432,14 +432,15 @@ func (s *updateSellOrdersSuite) sellOrderSetup(count int) {
totalQuantity = t.String()
}

err := s.baseStore.ClassTable().Insert(s.ctx, &baseapi.Class{
clsId, err := s.baseStore.ClassTable().InsertReturningID(s.ctx, &baseapi.Class{
Id: s.classID,
CreditTypeAbbrev: s.creditTypeAbbrev,
})
require.NoError(s.t, err)

batchKey, err := s.baseStore.BatchTable().InsertReturningID(s.ctx, &baseapi.Batch{
Denom: s.batchDenom,
Denom: s.batchDenom,
ClassKey: clsId,
})
require.NoError(s.t, err)

Expand Down Expand Up @@ -489,7 +490,7 @@ func (s *updateSellOrdersSuite) sellOrderSetup(count int) {
func (s *updateSellOrdersSuite) aliceBatchBalance() {
batch, err := s.baseStore.BatchTable().GetByDenom(s.ctx, s.batchDenom)
if err == ormerrors.NotFound {
_, err := s.baseStore.ClassTable().InsertReturningID(s.ctx, &baseapi.Class{
clsKey, err := s.baseStore.ClassTable().InsertReturningID(s.ctx, &baseapi.Class{
Id: s.classID,
CreditTypeAbbrev: s.creditTypeAbbrev,
})
Expand All @@ -500,6 +501,7 @@ func (s *updateSellOrdersSuite) aliceBatchBalance() {

batchKey, err := s.baseStore.BatchTable().InsertReturningID(s.ctx, &baseapi.Batch{
ProjectKey: projectKey,
ClassKey: clsKey,
Denom: s.batchDenom,
})
require.NoError(s.t, err)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ func TestSellOrdersByBatch(t *testing.T) {
otherDenom := "C01-19990101-20290101-001"
assert.NilError(t, s.baseStore.BatchTable().Insert(s.ctx, &ecocreditApi.Batch{
ProjectKey: 1,
ClassKey: s.classId,
Denom: otherDenom,
Metadata: "",
StartDate: nil,
Expand Down
2 changes: 2 additions & 0 deletions x/ecocredit/simulation/genesis.go
Original file line number Diff line number Diff line change
Expand Up @@ -330,6 +330,7 @@ func genGenesisState(ctx context.Context, simState *module.SimulationState, ss a
&api.Batch{
Issuer: accs[0].Address,
ProjectKey: pKey1,
ClassKey: cKey1,
Denom: denom,
StartDate: timestamppb.New(startDate),
EndDate: timestamppb.New(endDate),
Expand All @@ -354,6 +355,7 @@ func genGenesisState(ctx context.Context, simState *module.SimulationState, ss a
&api.Batch{
Issuer: accs[2].Address,
ProjectKey: pKey2,
ClassKey: cKey2,
Denom: denom,
StartDate: timestamppb.New(startDate.UTC()),
EndDate: timestamppb.New(endDate.UTC()),
Expand Down

0 comments on commit a5aa435

Please sign in to comment.