Skip to content

Commit

Permalink
Create bank contract to reuse and remove extra event
Browse files Browse the repository at this point in the history
  • Loading branch information
Jrigada committed Nov 29, 2024
1 parent be4764e commit 7afdb1a
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 24 deletions.
14 changes: 2 additions & 12 deletions crates/forge/tests/fixtures/zk/Constructor.s.sol
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
pragma solidity ^0.8.18;

import {Script} from "forge-std/Script.sol";
import {Bank} from "../src/Bank.sol";

contract ConstructorScript is Script {
function run() external {
Expand All @@ -21,15 +22,4 @@ contract ConstructorScript is Script {

vm.stopBroadcast();
}
}

contract Bank {
event Received(address sender, uint256 amount);

function balance() public view returns (uint256) {
return address(this).balance;
}

constructor() payable {
}
}
}
1 change: 1 addition & 0 deletions crates/forge/tests/it/zk/constructor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,4 +32,5 @@ fn setup_deploy_prj(prj: &mut TestProject) {
util::initialize(prj.root());
prj.add_script("Constructor.s.sol", include_str!("../../fixtures/zk/Constructor.s.sol"))
.unwrap();
prj.add_source("Bank.sol", include_str!("../../../../../testdata/zk/Bank.sol")).unwrap();
}
12 changes: 12 additions & 0 deletions testdata/zk/Bank.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
// SPDX-License-Identifier: UNLICENSED
pragma solidity ^0.8.18;

contract Bank {
function balance() public view returns (uint256) {
return address(this).balance;
}

constructor() payable {}

receive() external payable {}
}
13 changes: 1 addition & 12 deletions testdata/zk/Constructor.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -4,20 +4,9 @@ pragma solidity ^0.8.18;
import "ds-test/test.sol";
import "../cheats/Vm.sol";
import "../default/logs/console.sol";

contract Bank {
function balance() public view returns (uint256) {
return address(this).balance;
}

constructor() payable {}

receive() external payable {}
}
import "./Bank.sol";

contract ZkConstructorTest is DSTest {
Vm constant vm = Vm(HEVM_ADDRESS);

function testZkConstructorWorksWithValue() public {
Bank bank = new Bank{value: 1 ether}();
assertEq(bank.balance(), 1 ether);
Expand Down

0 comments on commit 7afdb1a

Please sign in to comment.