diff --git a/package.json b/package.json index a776fc4..3656989 100644 --- a/package.json +++ b/package.json @@ -4,7 +4,9 @@ "name": "@buttergov/molten-core", "version": "0.1.0", "description": "Molten core contracts", - "files": ["out/"], + "files": [ + "out/" + ], "directories": { "lib": "lib", "test": "test" diff --git a/src/MoltenCampaign.sol b/src/MoltenCampaign.sol index 3738701..d0422b2 100644 --- a/src/MoltenCampaign.sol +++ b/src/MoltenCampaign.sol @@ -10,7 +10,7 @@ contract MoltenCampaignMarket { // Threshold in daoToken-weis. uint256 public threshold; - constructor (address daoTokenAddress, uint256 _threshold) { + constructor(address daoTokenAddress, uint256 _threshold) { daoToken = IERC20Votes(daoTokenAddress); threshold = _threshold; } @@ -19,11 +19,11 @@ contract MoltenCampaignMarket { contract MoltenCampaign { address public representative; MoltenCampaignMarket public market; - + uint256 public totalDeposited; mapping(address => uint256) public deposited; - constructor (address marketAddress) { + constructor(address marketAddress) { representative = msg.sender; market = MoltenCampaignMarket(marketAddress); } @@ -32,14 +32,14 @@ contract MoltenCampaign { return IERC20Votes(market.daoToken()); } - function deposit (uint256 amount) public { + function deposit(uint256 amount) public { deposited[msg.sender] += amount; totalDeposited += amount; _getDaoToken().transferFrom(msg.sender, address(this), amount); } - - function refund () public { + + function refund() public { uint256 _deposited = deposited[msg.sender]; deposited[msg.sender] = 0; diff --git a/test/MoltenCampaign.t.sol b/test/MoltenCampaign.t.sol index 8b54d78..d06527b 100644 --- a/test/MoltenCampaign.t.sol +++ b/test/MoltenCampaign.t.sol @@ -6,9 +6,9 @@ import {ERC20VotesMintableMock, ERC20VotesMintableFailedMock} from "./helpers/ER import {MoltenCampaign, MoltenCampaignMarket} from "../src/MoltenCampaign.sol"; contract CreationTest is Test { - MoltenCampaignMarket mcm; - ERC20VotesMintableMock daoToken; - uint256 threshold; + MoltenCampaignMarket public mcm; + ERC20VotesMintableMock public daoToken; + uint256 public threshold; function setUp() public { daoToken = new ERC20VotesMintableMock("DAO governance token", "GT"); @@ -31,42 +31,47 @@ contract CreationTest is Test { } abstract contract TestBase is Test { - ERC20VotesMintableMock daoToken; - uint256 threshold; - address representative = address(0x123); - MoltenCampaign mc; + ERC20VotesMintableMock public daoToken; + uint256 public threshold; + address public representative = address(0x123); + MoltenCampaign public mc; function setUp() public virtual { daoToken = new ERC20VotesMintableMock("DAO governance token", "GT"); threshold = 1; MoltenCampaignMarket mcm = new MoltenCampaignMarket( address(daoToken), - threshold); + threshold + ); vm.prank(representative); mc = new MoltenCampaign(address(mcm)); } } abstract contract TestBaseFailing is Test { - ERC20VotesMintableFailedMock daoToken; - uint256 threshold; - address representative = address(0x123); - MoltenCampaign mc; + ERC20VotesMintableFailedMock public daoToken; + uint256 public threshold; + address public representative = address(0x123); + MoltenCampaign public mc; function setUp() public virtual { - daoToken = new ERC20VotesMintableFailedMock("DAO governance token", "GT"); + daoToken = new ERC20VotesMintableFailedMock( + "DAO governance token", + "GT" + ); threshold = 1; MoltenCampaignMarket mcm = new MoltenCampaignMarket( address(daoToken), - threshold); + threshold + ); vm.prank(representative); mc = new MoltenCampaign(address(mcm)); } } contract DepositTest is TestBase { - address depositor; - address depositor2; + address public depositor; + address public depositor2; function setUp() public override { super.setUp(); @@ -78,7 +83,7 @@ contract DepositTest is TestBase { function testSuccessfulDepositUpdatesDeposited() public { vm.prank(depositor); mc.deposit(333); - + assertEq(mc.deposited(depositor), 333); } @@ -88,7 +93,7 @@ contract DepositTest is TestBase { vm.prank(depositor2); mc.deposit(222); - + assertEq(mc.totalDeposited(), 555); } @@ -96,16 +101,17 @@ contract DepositTest is TestBase { vm.prank(depositor); mc.deposit(333); - (address from, address to, uint256 amount) = daoToken.transferFromCalledWith(); + (address from, address to, uint256 amount) = daoToken + .transferFromCalledWith(); assertEq(from, depositor); assertEq(to, address(mc)); assertEq(amount, 333); } } - + contract DepositFailTest is TestBaseFailing { - address depositor; - address depositor2; + address public depositor; + address public depositor2; function setUp() public override { super.setUp(); @@ -113,6 +119,7 @@ contract DepositFailTest is TestBaseFailing { depositor = address(0x331); depositor2 = address(0x332); } + function testUnsuccessfulDepositDoesntUpdate() public { vm.prank(depositor); vm.expectRevert("ERC20VotesMintableFailedMock transferFrom"); @@ -124,8 +131,8 @@ contract DepositFailTest is TestBaseFailing { } contract RefundTest is TestBase { - address depositor; - address depositor2; + address public depositor; + address public depositor2; function setUp() public override { super.setUp(); @@ -142,7 +149,6 @@ contract RefundTest is TestBase { function testSuccessfulRefundUpdatesDeposited() public { vm.prank(depositor); mc.refund(); - assertEq(mc.deposited(depositor), 0); } @@ -152,7 +158,7 @@ contract RefundTest is TestBase { vm.prank(depositor2); mc.refund(); - + assertEq(mc.totalDeposited(), 0); } @@ -160,7 +166,8 @@ contract RefundTest is TestBase { vm.prank(depositor); mc.refund(); - (address from, address to, uint256 amount) = daoToken.transferFromCalledWith(); + (address from, address to, uint256 amount) = daoToken + .transferFromCalledWith(); assertEq(from, address(mc)); assertEq(to, depositor); assertEq(amount, 333); diff --git a/test/MoltenCampaignMarket.t.sol b/test/MoltenCampaignMarket.t.sol index 7ebe9aa..892acbe 100644 --- a/test/MoltenCampaignMarket.t.sol +++ b/test/MoltenCampaignMarket.t.sol @@ -14,13 +14,19 @@ contract CreationTest is Test { } function testHasDaoToken() public { - MoltenCampaignMarket mcm = new MoltenCampaignMarket(address(daoToken), 1); + MoltenCampaignMarket mcm = new MoltenCampaignMarket( + address(daoToken), + 1 + ); assertEq(address(mcm.daoToken()), address(daoToken)); } function testHasThreshold(uint256 threshold) public { - MoltenCampaignMarket mcm = new MoltenCampaignMarket(address(daoToken), threshold); + MoltenCampaignMarket mcm = new MoltenCampaignMarket( + address(daoToken), + threshold + ); assertEq(mcm.threshold(), threshold); } diff --git a/test/helpers/ERC20VotesMintable.sol b/test/helpers/ERC20VotesMintable.sol index a8808d7..7846b91 100644 --- a/test/helpers/ERC20VotesMintable.sol +++ b/test/helpers/ERC20VotesMintable.sol @@ -47,7 +47,11 @@ contract ERC20VotesMintableMock is ERC20Votes { address to, uint256 amount ) public override returns (bool) { - transferFromCalledWith = TransferFromCall({from: from, to: to, amount: amount}); + transferFromCalledWith = TransferFromCall({ + from: from, + to: to, + amount: amount + }); return true; } } @@ -74,8 +78,12 @@ contract ERC20VotesMintableFailedMock is ERC20Votes { address to, uint256 amount ) public override returns (bool) { - transferFromCalledWith = TransferFromCall({from: from, to: to, amount: amount}); - require(false, "ERC20VotesMintableFailedMock transferFrom"); + transferFromCalledWith = TransferFromCall({ + from: from, + to: to, + amount: amount + }); + require(false, "ERC20VMFM transferFrom"); return true; } }