Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
M
mybee
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
vicotor
mybee
Commits
e039dab6
Unverified
Commit
e039dab6
authored
Sep 26, 2020
by
Ralph Pichler
Committed by
GitHub
Sep 26, 2020
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
account for totalPaidOut in liquidity check (#758)
parent
a3aedb96
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
78 additions
and
1 deletion
+78
-1
bindings.go
pkg/settlement/swap/chequebook/bindings.go
+1
-0
chequestore.go
pkg/settlement/swap/chequebook/chequestore.go
+8
-1
chequestore_test.go
pkg/settlement/swap/chequebook/chequestore_test.go
+64
-0
common_test.go
pkg/settlement/swap/chequebook/common_test.go
+5
-0
No files found.
pkg/settlement/swap/chequebook/bindings.go
View file @
e039dab6
...
@@ -18,6 +18,7 @@ type SimpleSwapBinding interface {
...
@@ -18,6 +18,7 @@ type SimpleSwapBinding interface {
Balance
(
*
bind
.
CallOpts
)
(
*
big
.
Int
,
error
)
Balance
(
*
bind
.
CallOpts
)
(
*
big
.
Int
,
error
)
Issuer
(
*
bind
.
CallOpts
)
(
common
.
Address
,
error
)
Issuer
(
*
bind
.
CallOpts
)
(
common
.
Address
,
error
)
TotalPaidOut
(
*
bind
.
CallOpts
)
(
*
big
.
Int
,
error
)
TotalPaidOut
(
*
bind
.
CallOpts
)
(
*
big
.
Int
,
error
)
PaidOut
(
*
bind
.
CallOpts
,
common
.
Address
)
(
*
big
.
Int
,
error
)
}
}
type
SimpleSwapBindingFunc
=
func
(
common
.
Address
,
bind
.
ContractBackend
)
(
SimpleSwapBinding
,
error
)
type
SimpleSwapBindingFunc
=
func
(
common
.
Address
,
bind
.
ContractBackend
)
(
SimpleSwapBinding
,
error
)
...
...
pkg/settlement/swap/chequebook/chequestore.go
View file @
e039dab6
...
@@ -167,7 +167,14 @@ func (s *chequeStore) ReceiveCheque(ctx context.Context, cheque *SignedCheque) (
...
@@ -167,7 +167,14 @@ func (s *chequeStore) ReceiveCheque(ctx context.Context, cheque *SignedCheque) (
return
nil
,
err
return
nil
,
err
}
}
if
balance
.
Cmp
(
cheque
.
CumulativePayout
)
<
0
{
alreadyPaidOut
,
err
:=
binding
.
PaidOut
(
&
bind
.
CallOpts
{
Context
:
ctx
,
},
s
.
beneficiary
)
if
err
!=
nil
{
return
nil
,
err
}
if
balance
.
Cmp
(
big
.
NewInt
(
0
)
.
Sub
(
cheque
.
CumulativePayout
,
alreadyPaidOut
))
<
0
{
return
nil
,
ErrBouncingCheque
return
nil
,
ErrBouncingCheque
}
}
...
...
pkg/settlement/swap/chequebook/chequestore_test.go
View file @
e039dab6
...
@@ -63,6 +63,12 @@ func TestReceiveCheque(t *testing.T) {
...
@@ -63,6 +63,12 @@ func TestReceiveCheque(t *testing.T) {
balance
:
func
(
*
bind
.
CallOpts
)
(
*
big
.
Int
,
error
)
{
balance
:
func
(
*
bind
.
CallOpts
)
(
*
big
.
Int
,
error
)
{
return
cumulativePayout2
,
nil
return
cumulativePayout2
,
nil
},
},
paidOut
:
func
(
o
*
bind
.
CallOpts
,
b
common
.
Address
)
(
*
big
.
Int
,
error
)
{
if
b
!=
beneficiary
{
t
.
Fatalf
(
"checking for wrong beneficiary. wanted %x, got %x"
,
beneficiary
,
b
)
}
return
big
.
NewInt
(
0
),
nil
},
},
nil
},
nil
},
},
func
(
c
*
chequebook
.
SignedCheque
,
cid
int64
)
(
common
.
Address
,
error
)
{
func
(
c
*
chequebook
.
SignedCheque
,
cid
int64
)
(
common
.
Address
,
error
)
{
...
@@ -186,6 +192,9 @@ func TestReceiveChequeInvalidAmount(t *testing.T) {
...
@@ -186,6 +192,9 @@ func TestReceiveChequeInvalidAmount(t *testing.T) {
balance
:
func
(
*
bind
.
CallOpts
)
(
*
big
.
Int
,
error
)
{
balance
:
func
(
*
bind
.
CallOpts
)
(
*
big
.
Int
,
error
)
{
return
cumulativePayout
,
nil
return
cumulativePayout
,
nil
},
},
paidOut
:
func
(
o
*
bind
.
CallOpts
,
b
common
.
Address
)
(
*
big
.
Int
,
error
)
{
return
big
.
NewInt
(
0
),
nil
},
},
nil
},
nil
},
},
func
(
c
*
chequebook
.
SignedCheque
,
cid
int64
)
(
common
.
Address
,
error
)
{
func
(
c
*
chequebook
.
SignedCheque
,
cid
int64
)
(
common
.
Address
,
error
)
{
...
@@ -247,6 +256,9 @@ func TestReceiveChequeInvalidChequebook(t *testing.T) {
...
@@ -247,6 +256,9 @@ func TestReceiveChequeInvalidChequebook(t *testing.T) {
balance
:
func
(
*
bind
.
CallOpts
)
(
*
big
.
Int
,
error
)
{
balance
:
func
(
*
bind
.
CallOpts
)
(
*
big
.
Int
,
error
)
{
return
cumulativePayout
,
nil
return
cumulativePayout
,
nil
},
},
paidOut
:
func
(
o
*
bind
.
CallOpts
,
b
common
.
Address
)
(
*
big
.
Int
,
error
)
{
return
big
.
NewInt
(
0
),
nil
},
},
nil
},
nil
},
},
func
(
c
*
chequebook
.
SignedCheque
,
cid
int64
)
(
common
.
Address
,
error
)
{
func
(
c
*
chequebook
.
SignedCheque
,
cid
int64
)
(
common
.
Address
,
error
)
{
...
@@ -339,6 +351,9 @@ func TestReceiveChequeInsufficientBalance(t *testing.T) {
...
@@ -339,6 +351,9 @@ func TestReceiveChequeInsufficientBalance(t *testing.T) {
balance
:
func
(
*
bind
.
CallOpts
)
(
*
big
.
Int
,
error
)
{
balance
:
func
(
*
bind
.
CallOpts
)
(
*
big
.
Int
,
error
)
{
return
big
.
NewInt
(
0
)
.
Sub
(
cumulativePayout
,
big
.
NewInt
(
1
)),
nil
return
big
.
NewInt
(
0
)
.
Sub
(
cumulativePayout
,
big
.
NewInt
(
1
)),
nil
},
},
paidOut
:
func
(
o
*
bind
.
CallOpts
,
b
common
.
Address
)
(
*
big
.
Int
,
error
)
{
return
big
.
NewInt
(
0
),
nil
},
},
nil
},
nil
},
},
func
(
c
*
chequebook
.
SignedCheque
,
cid
int64
)
(
common
.
Address
,
error
)
{
func
(
c
*
chequebook
.
SignedCheque
,
cid
int64
)
(
common
.
Address
,
error
)
{
...
@@ -357,3 +372,52 @@ func TestReceiveChequeInsufficientBalance(t *testing.T) {
...
@@ -357,3 +372,52 @@ func TestReceiveChequeInsufficientBalance(t *testing.T) {
t
.
Fatalf
(
"wrong error. wanted %v, got %v"
,
chequebook
.
ErrBouncingCheque
,
err
)
t
.
Fatalf
(
"wrong error. wanted %v, got %v"
,
chequebook
.
ErrBouncingCheque
,
err
)
}
}
}
}
func
TestReceiveChequeSufficientBalancePaidOut
(
t
*
testing
.
T
)
{
store
:=
storemock
.
NewStateStore
()
beneficiary
:=
common
.
HexToAddress
(
"0xffff"
)
issuer
:=
common
.
HexToAddress
(
"0xbeee"
)
cumulativePayout
:=
big
.
NewInt
(
10
)
chequebookAddress
:=
common
.
HexToAddress
(
"0xeeee"
)
sig
:=
make
([]
byte
,
65
)
chainID
:=
int64
(
1
)
chequestore
:=
chequebook
.
NewChequeStore
(
store
,
&
backendMock
{},
&
factoryMock
{
verifyChequebook
:
func
(
ctx
context
.
Context
,
address
common
.
Address
)
error
{
return
nil
},
},
chainID
,
beneficiary
,
func
(
address
common
.
Address
,
b
bind
.
ContractBackend
)
(
chequebook
.
SimpleSwapBinding
,
error
)
{
return
&
simpleSwapBindingMock
{
issuer
:
func
(
*
bind
.
CallOpts
)
(
common
.
Address
,
error
)
{
return
issuer
,
nil
},
balance
:
func
(
*
bind
.
CallOpts
)
(
*
big
.
Int
,
error
)
{
return
big
.
NewInt
(
0
)
.
Sub
(
cumulativePayout
,
big
.
NewInt
(
100
)),
nil
},
paidOut
:
func
(
o
*
bind
.
CallOpts
,
b
common
.
Address
)
(
*
big
.
Int
,
error
)
{
return
big
.
NewInt
(
100
),
nil
},
},
nil
},
func
(
c
*
chequebook
.
SignedCheque
,
cid
int64
)
(
common
.
Address
,
error
)
{
return
issuer
,
nil
})
_
,
err
:=
chequestore
.
ReceiveCheque
(
context
.
Background
(),
&
chequebook
.
SignedCheque
{
Cheque
:
chequebook
.
Cheque
{
Beneficiary
:
beneficiary
,
CumulativePayout
:
cumulativePayout
,
Chequebook
:
chequebookAddress
,
},
Signature
:
sig
,
})
if
err
!=
nil
{
t
.
Fatal
(
err
)
}
}
pkg/settlement/swap/chequebook/common_test.go
View file @
e039dab6
...
@@ -101,6 +101,7 @@ type simpleSwapBindingMock struct {
...
@@ -101,6 +101,7 @@ type simpleSwapBindingMock struct {
balance
func
(
*
bind
.
CallOpts
)
(
*
big
.
Int
,
error
)
balance
func
(
*
bind
.
CallOpts
)
(
*
big
.
Int
,
error
)
issuer
func
(
*
bind
.
CallOpts
)
(
common
.
Address
,
error
)
issuer
func
(
*
bind
.
CallOpts
)
(
common
.
Address
,
error
)
totalPaidOut
func
(
o
*
bind
.
CallOpts
)
(
*
big
.
Int
,
error
)
totalPaidOut
func
(
o
*
bind
.
CallOpts
)
(
*
big
.
Int
,
error
)
paidOut
func
(
*
bind
.
CallOpts
,
common
.
Address
)
(
*
big
.
Int
,
error
)
}
}
func
(
m
*
simpleSwapBindingMock
)
Balance
(
o
*
bind
.
CallOpts
)
(
*
big
.
Int
,
error
)
{
func
(
m
*
simpleSwapBindingMock
)
Balance
(
o
*
bind
.
CallOpts
)
(
*
big
.
Int
,
error
)
{
...
@@ -115,6 +116,10 @@ func (m *simpleSwapBindingMock) TotalPaidOut(o *bind.CallOpts) (*big.Int, error)
...
@@ -115,6 +116,10 @@ func (m *simpleSwapBindingMock) TotalPaidOut(o *bind.CallOpts) (*big.Int, error)
return
m
.
totalPaidOut
(
o
)
return
m
.
totalPaidOut
(
o
)
}
}
func
(
m
*
simpleSwapBindingMock
)
PaidOut
(
o
*
bind
.
CallOpts
,
c
common
.
Address
)
(
*
big
.
Int
,
error
)
{
return
m
.
paidOut
(
o
,
c
)
}
type
erc20BindingMock
struct
{
type
erc20BindingMock
struct
{
balanceOf
func
(
*
bind
.
CallOpts
,
common
.
Address
)
(
*
big
.
Int
,
error
)
balanceOf
func
(
*
bind
.
CallOpts
,
common
.
Address
)
(
*
big
.
Int
,
error
)
}
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment