-
-
Save anonymous/2d10e87e125ba0bade046e5c87d9374b to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
pragma solidity ^0.4.11; | |
import "ds-test/test.sol"; | |
import "./EtherToken.sol"; | |
contract AssetTest is DSTest { | |
EtherToken etherToken; | |
uint preminedAmount = 10 ** 28; | |
function setUp() { | |
etherToken = new EtherToken(); | |
} | |
function testPreminedAmountCorrect() { | |
assertEq(etherToken.balanceOf(this), preminedAmount); | |
} | |
function testDeposit() { | |
uint depositAmount = 1 ether; | |
uint preTokenBalance = etherToken.balanceOf(this); | |
uint preEthBalance = this.balance; | |
etherToken.deposit.value(depositAmount)(); | |
uint postTokenBalance = etherToken.balanceOf(this); | |
uint postEthBalance = this.balance; | |
uint tokenIncrease = postTokenBalance - preTokenBalance; | |
uint ethDecrease = preEthBalance - postEthBalance; | |
assertEq(tokenIncrease, depositAmount); | |
assertEq(ethDecrease, depositAmount); | |
} | |
function testWithdraw() { | |
uint withdrawAmount = 500 finney; | |
uint preTokenBalance = etherToken.balanceOf(this); | |
uint preEthBalance = this.balance; | |
etherToken.withdraw(withdrawAmount); | |
uint postTokenBalance = etherToken.balanceOf(this); | |
uint postEthBalance = this.balance; | |
uint tokenDecrease = preTokenBalance - postTokenBalance; | |
uint ethIncrease = postEthBalance - preEthBalance; | |
assertEq(tokenDecrease, withdrawAmount); | |
assertEq(ethIncrease, withdrawAmount); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment