Skip to content

Commit 0209b88

Browse files
committed
loans: Update mocks and add more unit tests
1 parent 613ca54 commit 0209b88

File tree

6 files changed

+452
-40
lines changed

6 files changed

+452
-40
lines changed

.github/workflows/build.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
# build workflow builds docker images, pushes images to docker hub and updates swagger API
22
on:
33
push:
4-
branches: [main, invest-endpoint-loan-retrieval-fix]
4+
branches: [main]
55
name: Build
66
jobs:
77
build:

go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ require (
66
github.com/ChainSafe/go-schnorrkel v1.0.0
77
github.com/Masterminds/semver v1.5.0
88
github.com/centrifuge/centrifuge-protobufs v1.0.0
9-
github.com/centrifuge/chain-custom-types v1.0.8
9+
github.com/centrifuge/chain-custom-types v1.0.9
1010
github.com/centrifuge/go-substrate-rpc-client/v4 v4.1.0
1111
github.com/centrifuge/gocelery/v2 v2.0.0-20221101190423-3b07af1b49a6
1212
github.com/centrifuge/precise-proofs v1.0.0

go.sum

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -126,8 +126,8 @@ github.com/cenkalti/backoff v2.2.1+incompatible/go.mod h1:90ReRw6GdpyfrHakVjL/QH
126126
github.com/census-instrumentation/opencensus-proto v0.2.1/go.mod h1:f6KPmirojxKA12rnyqOA5BBL4O983OfeGPqjHWSTneU=
127127
github.com/centrifuge/centrifuge-protobufs v1.0.0 h1:ZPg0XpkTrGrjQu8scXjMGs7jjqsWPiXmOXdV/bz30ng=
128128
github.com/centrifuge/centrifuge-protobufs v1.0.0/go.mod h1:VL6mcnK6vTRiFljHP39J0WBI3Uu5BHQjhdFkCxY9/9I=
129-
github.com/centrifuge/chain-custom-types v1.0.8 h1:JcXQNzjzs1y/xEBK23XlRJeD1OxLZByfnwstQkORuIg=
130-
github.com/centrifuge/chain-custom-types v1.0.8/go.mod h1:kSUJ3O83vaLutJIiaEfqwn3lfTaisn/G/baS8WrycTg=
129+
github.com/centrifuge/chain-custom-types v1.0.9 h1:utkYu/8Tgze6xktHMZ9wgcDHXUsM2yWuwSHL2YqfZ+8=
130+
github.com/centrifuge/chain-custom-types v1.0.9/go.mod h1:kSUJ3O83vaLutJIiaEfqwn3lfTaisn/G/baS8WrycTg=
131131
github.com/centrifuge/go-merkle v0.0.0-20190727075423-0ac78bbbc01b h1:TPvvMcGAc3TVBVgQ4XYYEWTXxYls8YuylZ8JzrVxPzc=
132132
github.com/centrifuge/go-merkle v0.0.0-20190727075423-0ac78bbbc01b/go.mod h1:0voJY6Qzxvr2S0LeDSFQiCnJzGq5gORg2SwCmn8602I=
133133
github.com/centrifuge/go-substrate-rpc-client/v4 v4.1.0 h1:GEvub7kU5YFAcn5A2uOo4AZSM1/cWZCOvfu7E3gQmK8=

pallets/loans/api.go

Lines changed: 6 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -39,41 +39,15 @@ type CreatedLoanStorageEntry struct {
3939

4040
type ActiveLoanStorageEntry struct {
4141
LoanID types.U64
42-
ActiveLoan ActiveLoan
43-
}
44-
45-
type ActiveLoan struct {
46-
Schedule loans.RepaymentSchedule
47-
Collateral loans.Asset
48-
Restrictions loans.LoanRestrictions
49-
Borrower types.AccountID
50-
WriteOffPercentage types.U128
51-
OriginationDate types.U64
52-
Pricing loans.Pricing
53-
TotalBorrowed types.U128
54-
TotalRepaid RepaidAmount
55-
RepaymentsOnScheduleUntil types.U64
56-
}
57-
58-
type RepaidAmount struct {
59-
Principal types.U128
60-
Interest types.U128
61-
Unscheduled types.U128
62-
}
63-
64-
type ClosedLoan struct {
65-
ClosedAt types.U32
66-
Info loans.LoanInfo
67-
TotalBorrowed types.U128
68-
TotalRepaid RepaidAmount
42+
ActiveLoan loans.ActiveLoan
6943
}
7044

7145
//go:generate mockery --name API --structname APIMock --filename api_mock.go --inpackage
7246

7347
type API interface {
7448
GetCreatedLoan(poolID types.U64, loanID types.U64) (*CreatedLoanStorageEntry, error)
75-
GetActiveLoan(poolID types.U64, loanID types.U64) (*ActiveLoan, error)
76-
GetClosedLoan(poolID types.U64, loanID types.U64) (*ClosedLoan, error)
49+
GetActiveLoan(poolID types.U64, loanID types.U64) (*loans.ActiveLoan, error)
50+
GetClosedLoan(poolID types.U64, loanID types.U64) (*loans.ClosedLoan, error)
7751
}
7852

7953
type api struct {
@@ -152,7 +126,7 @@ func (a *api) GetCreatedLoan(poolID types.U64, loanID types.U64) (*CreatedLoanSt
152126
return &createdLoan, nil
153127
}
154128

155-
func (a *api) GetActiveLoan(poolID types.U64, loanID types.U64) (*ActiveLoan, error) {
129+
func (a *api) GetActiveLoan(poolID types.U64, loanID types.U64) (*loans.ActiveLoan, error) {
156130
err := validation.Validate(
157131
validation.NewValidator(poolID, validation.U64ValidationFn),
158132
)
@@ -219,7 +193,7 @@ func (a *api) GetActiveLoan(poolID types.U64, loanID types.U64) (*ActiveLoan, er
219193
return nil, ErrActiveLoanNotFound
220194
}
221195

222-
func (a *api) GetClosedLoan(poolID types.U64, loanID types.U64) (*ClosedLoan, error) {
196+
func (a *api) GetClosedLoan(poolID types.U64, loanID types.U64) (*loans.ClosedLoan, error) {
223197
err := validation.Validate(
224198
validation.NewValidator(poolID, validation.U64ValidationFn),
225199
)
@@ -268,7 +242,7 @@ func (a *api) GetClosedLoan(poolID types.U64, loanID types.U64) (*ClosedLoan, er
268242
return nil, errors.ErrStorageKeyCreation
269243
}
270244

271-
var closedLoan ClosedLoan
245+
var closedLoan loans.ClosedLoan
272246

273247
ok, err := a.centAPI.GetStorageLatest(storageKey, &closedLoan)
274248

pallets/loans/api_mock.go

Lines changed: 47 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)