mirror of
https://github.com/status-im/nim-codex.git
synced 2025-02-18 05:36:50 +00:00
Integrate dagger contracts from `nim-dagger-contracts` repo. Add `dagger-contracts`, `nim-web3`, and all of `nim-web3`’s transitive deps as submodule deps to `nim-dagger`. Note: `nim-web3` and its transitive deps may no longer be needed when we switch to `nim-ethers`. Add a `testContracts` nimble task to test all of the contracts functionality. Namely, this spins up an ethereum simulator, deploys the contracts (in `dagger-contracts`), runs the contract tests, and finally, regardless of success/error, kills the ethereum sim processes. The nimble task can be run with `./env.sh nimble testContracts`. We also tested `nim-dagger-contracts` as a submodule dep of `nim-dagger`, and while the tests run as expected, the preference is to merge `nim-dagger-contracts` inside of `nim-dagger` for ease of parallel development. There’s also a high probability that `nim-dagger-contracts` is not being used as a dep by other projects. Are there any strong objections to this? Co-authored-by: Michael Bradley <michaelsbradleyjr@gmail.com>
33 lines
999 B
Nim
33 lines
999 B
Nim
import pkg/chronos
|
|
import pkg/stint
|
|
import dagger/contracts
|
|
import dagger/contracts/testtoken
|
|
import ./ethertest
|
|
|
|
ethersuite "Staking":
|
|
|
|
let stakeAmount = 100.u256
|
|
|
|
var storage: Storage
|
|
var token: TestToken
|
|
|
|
setup:
|
|
let deployment = deployment()
|
|
storage = Storage.new(!deployment.address(Storage), provider.getSigner())
|
|
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 "withdraws stake":
|
|
await token.approve(storage.address, stakeAmount)
|
|
await storage.increaseStake(stakeAmount)
|
|
let balanceBefore = await token.balanceOf(accounts[0])
|
|
await storage.withdrawStake()
|
|
let balanceAfter = await token.balanceOf(accounts[0])
|
|
check (balanceAfter - balanceBefore) == stakeAmount
|