-
Notifications
You must be signed in to change notification settings - Fork 51
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore: add unit test cases for payment module
- Loading branch information
1 parent
9cd5a4c
commit e66a1f6
Showing
16 changed files
with
1,186 additions
and
155 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
package keeper_test | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/stretchr/testify/require" | ||
|
||
"github.com/bnb-chain/greenfield/testutil/sample" | ||
"github.com/bnb-chain/greenfield/x/payment/types" | ||
) | ||
|
||
func TestAutoResumeRecord(t *testing.T) { | ||
keeper, ctx, _ := makePaymentKeeper(t) | ||
|
||
addr1 := sample.RandAccAddress() | ||
record1 := &types.AutoResumeRecord{ | ||
Addr: addr1.String(), | ||
Timestamp: 100, | ||
} | ||
|
||
addr2 := sample.RandAccAddress() | ||
record2 := &types.AutoResumeRecord{ | ||
Addr: addr2.String(), | ||
Timestamp: 200, | ||
} | ||
|
||
// set | ||
keeper.SetAutoResumeRecord(ctx, record1) | ||
keeper.SetAutoResumeRecord(ctx, record2) | ||
|
||
// exits | ||
// before the timestamp | ||
exist := keeper.ExistsAutoResumeRecord(ctx, 90, addr1) | ||
require.True(t, !exist) | ||
exist = keeper.ExistsAutoResumeRecord(ctx, 101, addr1) | ||
require.True(t, exist) | ||
|
||
// at any time | ||
exist = keeper.ExistsAutoResumeRecord(ctx, 0, addr1) | ||
require.True(t, exist) | ||
exist = keeper.ExistsAutoResumeRecord(ctx, 0, addr2) | ||
require.True(t, exist) | ||
|
||
// remove | ||
keeper.RemoveAutoResumeRecord(ctx, record1.Timestamp, addr1) | ||
keeper.RemoveAutoResumeRecord(ctx, record2.Timestamp, addr2) | ||
|
||
exist = keeper.ExistsAutoResumeRecord(ctx, 0, addr1) | ||
require.True(t, !exist) | ||
exist = keeper.ExistsAutoResumeRecord(ctx, 0, addr2) | ||
require.True(t, !exist) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
package keeper_test | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/stretchr/testify/require" | ||
|
||
"github.com/bnb-chain/greenfield/testutil/sample" | ||
"github.com/bnb-chain/greenfield/x/payment/types" | ||
) | ||
|
||
func TestAutoSettleRecord(t *testing.T) { | ||
keeper, ctx, _ := makePaymentKeeper(t) | ||
|
||
addr1 := sample.RandAccAddress() | ||
record1 := &types.AutoSettleRecord{ | ||
Addr: addr1.String(), | ||
Timestamp: 100, | ||
} | ||
|
||
addr2 := sample.RandAccAddress() | ||
record2 := &types.AutoSettleRecord{ | ||
Addr: addr2.String(), | ||
Timestamp: 200, | ||
} | ||
|
||
// set | ||
keeper.SetAutoSettleRecord(ctx, record1) | ||
keeper.SetAutoSettleRecord(ctx, record2) | ||
|
||
// update to new time | ||
keeper.UpdateAutoSettleRecord(ctx, addr1, record1.Timestamp, 110) | ||
|
||
// update to remove | ||
keeper.UpdateAutoSettleRecord(ctx, addr2, record2.Timestamp, 0) | ||
|
||
// get all | ||
records := keeper.GetAllAutoSettleRecord(ctx) | ||
require.True(t, len(records) == 1) | ||
require.True(t, records[0].Addr == addr1.String()) | ||
require.True(t, records[0].Timestamp == 110) | ||
} |
Oops, something went wrong.