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