Skip to content
This repository has been archived by the owner on Mar 12, 2024. It is now read-only.

Commit

Permalink
refactor(contracts): minimize diff
Browse files Browse the repository at this point in the history
  • Loading branch information
guidanoli committed Aug 1, 2023
1 parent f68e37c commit c08086c
Showing 1 changed file with 15 additions and 15 deletions.
30 changes: 15 additions & 15 deletions onchain/rollups/test/foundry/dapp/CartesiDApp.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,11 @@ import {IERC20} from "@openzeppelin/contracts/token/ERC20/IERC20.sol";
import {IERC721} from "@openzeppelin/contracts/token/ERC721/IERC721.sol";
import {IERC721Receiver} from "@openzeppelin/contracts/token/ERC721/IERC721Receiver.sol";

import {LibServerManager} from "../util/LibServerManager.sol";
import {SimpleConsensus} from "../util/SimpleConsensus.sol";
import {SimpleERC20} from "../util/SimpleERC20.sol";
import {SimpleERC721} from "../util/SimpleERC721.sol";
import {SimpleERC721Receiver} from "../util/SimpleERC721Receiver.sol";
import {LibServerManager} from "../util/LibServerManager.sol";

import "forge-std/console.sol";

Expand Down Expand Up @@ -77,7 +77,7 @@ contract CartesiDAppTest is TestBase {
);
event NewConsensus(IConsensus newConsensus);

constructor() {
function setUp() public {
deployContracts();
generateOutputs();
writeInputs();
Expand Down Expand Up @@ -105,12 +105,12 @@ contract CartesiDAppTest is TestBase {
emit OwnershipTransferred(address(this), _owner);

// perform call to constructor
CartesiDApp newDApp = new CartesiDApp(consensus, _owner, _templateHash);
dapp = new CartesiDApp(consensus, _owner, _templateHash);

// check set values
assertEq(address(newDApp.getConsensus()), address(consensus));
assertEq(newDApp.owner(), _owner);
assertEq(newDApp.getTemplateHash(), _templateHash);
assertEq(address(dapp.getConsensus()), address(consensus));
assertEq(dapp.owner(), _owner);
assertEq(dapp.getTemplateHash(), _templateHash);
}

// test notices
Expand Down Expand Up @@ -495,35 +495,35 @@ contract CartesiDAppTest is TestBase {
vm.assume(address(_newOwner) != address(0));
vm.assume(_nonZeroAddress != address(0));

CartesiDApp newDApp = new CartesiDApp(consensus, _owner, _templateHash);
dapp = new CartesiDApp(consensus, _owner, _templateHash);

IConsensus newConsensus = new SimpleConsensus();

// migrate fail if not called from owner
vm.expectRevert("Ownable: caller is not the owner");
newDApp.migrateToConsensus(newConsensus);
dapp.migrateToConsensus(newConsensus);

// now impersonate owner
vm.prank(_owner);
vm.expectEmit(false, false, false, true, address(newDApp));
vm.expectEmit(false, false, false, true, address(dapp));
emit NewConsensus(newConsensus);
newDApp.migrateToConsensus(newConsensus);
assertEq(address(newDApp.getConsensus()), address(newConsensus));
dapp.migrateToConsensus(newConsensus);
assertEq(address(dapp.getConsensus()), address(newConsensus));

// if owner changes, then original owner no longer can migrate consensus
vm.prank(_owner);
newDApp.transferOwnership(_newOwner);
dapp.transferOwnership(_newOwner);
vm.expectRevert("Ownable: caller is not the owner");
vm.prank(_owner);
newDApp.migrateToConsensus(consensus);
dapp.migrateToConsensus(consensus);

// if new owner renounce ownership (give ownership to address 0)
// no one will be able to migrate consensus
vm.prank(_newOwner);
newDApp.renounceOwnership();
dapp.renounceOwnership();
vm.expectRevert("Ownable: caller is not the owner");
vm.prank(_nonZeroAddress);
newDApp.migrateToConsensus(consensus);
dapp.migrateToConsensus(consensus);
}

// Store proof in storage
Expand Down

0 comments on commit c08086c

Please sign in to comment.