From 87bd947d3d4bde752b839a661f47f9e6fa5e235c Mon Sep 17 00:00:00 2001 From: Mark Spanbroek Date: Tue, 15 Mar 2022 17:29:56 +0100 Subject: [PATCH] [contracts] Update to new collateral design --- dagger/contracts/storage.nim | 8 +++---- .../{testStaking.nim => testCollateral.nim} | 24 +++++++++---------- tests/testContracts.nim | 4 ++-- 3 files changed, 18 insertions(+), 18 deletions(-) rename tests/contracts/{testStaking.nim => testCollateral.nim} (50%) diff --git a/dagger/contracts/storage.nim b/dagger/contracts/storage.nim index ab2078d1..131428b0 100644 --- a/dagger/contracts/storage.nim +++ b/dagger/contracts/storage.nim @@ -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.} diff --git a/tests/contracts/testStaking.nim b/tests/contracts/testCollateral.nim similarity index 50% rename from tests/contracts/testStaking.nim rename to tests/contracts/testCollateral.nim index 4116ec2f..3af37f22 100644 --- a/tests/contracts/testStaking.nim +++ b/tests/contracts/testCollateral.nim @@ -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 diff --git a/tests/testContracts.nim b/tests/testContracts.nim index 668d6214..53dab0a1 100644 --- a/tests/testContracts.nim +++ b/tests/testContracts.nim @@ -1,5 +1,5 @@ import ./contracts/testMarketplace -import ./contracts/testStaking +import ./contracts/testCollateral import ./contracts/testContracts -{.warning[UnusedImport]:off.} \ No newline at end of file +{.warning[UnusedImport]:off.}