[contracts] Update to new collateral design
This commit is contained in:
parent
8d0f9775b5
commit
87bd947d3d
|
@ -11,10 +11,10 @@ type
|
|||
Storage* = ref object of Contract
|
||||
Id = array[32, byte]
|
||||
|
||||
proc stakeAmount*(storage: Storage): UInt256 {.contract, view.}
|
||||
proc increaseStake*(storage: Storage, amount: UInt256) {.contract.}
|
||||
proc withdrawStake*(storage: Storage) {.contract.}
|
||||
proc stake*(storage: Storage, account: Address): UInt256 {.contract, view.}
|
||||
proc collateralAmount*(storage: Storage): UInt256 {.contract, view.}
|
||||
proc deposit*(storage: Storage, amount: UInt256) {.contract.}
|
||||
proc withdraw*(storage: Storage) {.contract.}
|
||||
proc balanceOf*(storage: Storage, account: Address): UInt256 {.contract, view.}
|
||||
proc duration*(storage: Storage, id: Id): UInt256 {.contract, view.}
|
||||
proc size*(storage: Storage, id: Id): UInt256 {.contract, view.}
|
||||
proc contentHash*(storage: Storage, id: Id): array[32, byte] {.contract, view.}
|
||||
|
|
|
@ -4,9 +4,9 @@ import dagger/contracts
|
|||
import dagger/contracts/testtoken
|
||||
import ./ethertest
|
||||
|
||||
ethersuite "Staking":
|
||||
ethersuite "Collateral":
|
||||
|
||||
let stakeAmount = 100.u256
|
||||
let collateralAmount = 100.u256
|
||||
|
||||
var storage: Storage
|
||||
var token: TestToken
|
||||
|
@ -17,16 +17,16 @@ ethersuite "Staking":
|
|||
token = TestToken.new(!deployment.address(TestToken), provider.getSigner())
|
||||
await token.mint(accounts[0], 1000.u256)
|
||||
|
||||
test "increases stake":
|
||||
await token.approve(storage.address, stakeAmount)
|
||||
await storage.increaseStake(stakeAmount)
|
||||
let stake = await storage.stake(accounts[0])
|
||||
check stake == stakeAmount
|
||||
test "increases collateral":
|
||||
await token.approve(storage.address, collateralAmount)
|
||||
await storage.deposit(collateralAmount)
|
||||
let collateral = await storage.balanceOf(accounts[0])
|
||||
check collateral == collateralAmount
|
||||
|
||||
test "withdraws stake":
|
||||
await token.approve(storage.address, stakeAmount)
|
||||
await storage.increaseStake(stakeAmount)
|
||||
test "withdraws collateral":
|
||||
await token.approve(storage.address, collateralAmount)
|
||||
await storage.deposit(collateralAmount)
|
||||
let balanceBefore = await token.balanceOf(accounts[0])
|
||||
await storage.withdrawStake()
|
||||
await storage.withdraw()
|
||||
let balanceAfter = await token.balanceOf(accounts[0])
|
||||
check (balanceAfter - balanceBefore) == stakeAmount
|
||||
check (balanceAfter - balanceBefore) == collateralAmount
|
|
@ -1,5 +1,5 @@
|
|||
import ./contracts/testMarketplace
|
||||
import ./contracts/testStaking
|
||||
import ./contracts/testCollateral
|
||||
import ./contracts/testContracts
|
||||
|
||||
{.warning[UnusedImport]:off.}
|
||||
{.warning[UnusedImport]:off.}
|
||||
|
|
Loading…
Reference in New Issue