Skip to content

Commit

Permalink
[unit-test-settle-balance] updating tomoxlending/lendingstate/settle_…
Browse files Browse the repository at this point in the history
…balance_test.go
  • Loading branch information
thanhnguyennguyen committed Jun 16, 2020
1 parent f01528c commit 4da4aa3
Showing 1 changed file with 80 additions and 11 deletions.
91 changes: 80 additions & 11 deletions tomoxlending/lendingstate/settle_balance_test.go
Expand Up @@ -100,6 +100,7 @@ func TestGetSettleBalance(t *testing.T) {
lendQuantity, _ := new(big.Int).SetString("1000000000000000000000", 10) // 1000
fee, _ := new(big.Int).SetString("10000000000000000000", 10) // 10
lendQuantityExcluded, _ := new(big.Int).SetString("990000000000000000000", 10) // 990
lendTokenNotTomo := common.HexToAddress("0x0000000000000000000000000000000000000033")
collateral := common.HexToAddress("0x0000000000000000000000000000000000000022")
collateralLocked, _ := new(big.Int).SetString("1000000000000000000000", 10) // 1000
collateralLocked = new(big.Int).Mul(big.NewInt(150), collateralLocked)
Expand All @@ -125,7 +126,25 @@ func TestGetSettleBalance(t *testing.T) {
wantErr bool
}{
{
"quantityToLend = borrowFee",
"collateralPrice nil",
GetSettleBalanceArg{
true,
Borrowing,
common.BasePrice,
common.Big0,
big.NewInt(150),
big.NewInt(10000), // 100%
common.Address{},
common.Address{},
common.BasePrice,
common.BasePrice,
lendQuantity,
},
nil,
true,
},
{
"quantityToLend = borrowFee, taker BORROW",
GetSettleBalanceArg{
true,
Borrowing,
Expand All @@ -144,7 +163,7 @@ func TestGetSettleBalance(t *testing.T) {
},

{
"LendToken is TOMO, quantity too small",
"LendToken is TOMO, quantity too small, taker BORROW",
GetSettleBalanceArg{
true,
Borrowing,
Expand All @@ -162,7 +181,7 @@ func TestGetSettleBalance(t *testing.T) {
true,
},
{
"LendToken is not TOMO, quantity too small",
"LendToken is not TOMO, quantity too small, taker BORROW",
GetSettleBalanceArg{
true,
Borrowing,
Expand All @@ -181,26 +200,76 @@ func TestGetSettleBalance(t *testing.T) {
},

{
"LendToken is not TOMO, no error",
"LendToken is not TOMO, no error, taker BORROW",
GetSettleBalanceArg{
true,
Borrowing,
common.BasePrice,
common.BasePrice,
big.NewInt(150),
big.NewInt(100), // 1%
common.Address{},
common.Address{},
common.BasePrice,
lendTokenNotTomo,
collateral,
common.BasePrice,
common.BasePrice,
lendQuantity,
},
nil,
true,
&LendingSettleBalance{
Taker: TradeResult{
Fee: fee,
InToken: lendTokenNotTomo,
InTotal: lendQuantityExcluded,
OutToken: collateral,
OutTotal: collateralLocked,
},
Maker: TradeResult{
Fee: common.Big0,
InToken: common.Address{},
InTotal: common.Big0,
OutToken: lendTokenNotTomo,
OutTotal: lendQuantity,
},
CollateralLockedAmount: collateralLocked,
},
false,
},

{
"LendToken is TOMO, no error, invest",
"LendToken is not TOMO, no error, taker INVEST",
GetSettleBalanceArg{
true,
Investing,
common.BasePrice,
common.BasePrice,
big.NewInt(150),
big.NewInt(100), // 1%
lendTokenNotTomo,
collateral,
common.BasePrice,
common.BasePrice,
lendQuantity,
},
&LendingSettleBalance{
Maker: TradeResult{
Fee: fee,
InToken: lendTokenNotTomo,
InTotal: lendQuantityExcluded,
OutToken: collateral,
OutTotal: collateralLocked,
},
Taker: TradeResult{
Fee: common.Big0,
InToken: common.Address{},
InTotal: common.Big0,
OutToken: lendTokenNotTomo,
OutTotal: lendQuantity,
},
CollateralLockedAmount: collateralLocked,
},
false,
},
{
"LendToken is TOMO, no error, taker invest",
GetSettleBalanceArg{
true,
Investing,
Expand Down Expand Up @@ -235,7 +304,7 @@ func TestGetSettleBalance(t *testing.T) {
},

{
"LendToken is TOMO, no error, Borrow",
"LendToken is TOMO, no error, taker Borrow",
GetSettleBalanceArg{
true,
Borrowing,
Expand Down

0 comments on commit 4da4aa3

Please sign in to comment.