Skip to content

Commit

Permalink
fix forge tests
Browse files Browse the repository at this point in the history
  • Loading branch information
joaquim-verges committed May 20, 2022
1 parent ae656d9 commit a603d4a
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 23 deletions.
49 changes: 31 additions & 18 deletions src/test/ByocRegistry.t.sol → src/test/ContractPublisher.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
pragma solidity ^0.8.0;

// Target contracts
import { ByocRegistry } from "contracts/ByocRegistry.sol";
import "contracts/interfaces/IByocRegistry.sol";
import { ContractPublisher } from "contracts/ContractPublisher.sol";
import "contracts/interfaces/IContractPublisher.sol";
import "contracts/TWRegistry.sol";

// Test helpers
Expand All @@ -18,7 +18,7 @@ contract MockCustomContract {
}
}

contract IByocRegistryData {
contract IContractPublisherData {
/// @dev Emitted when the registry is paused.
event Paused(bool isPaused);

Expand All @@ -29,7 +29,7 @@ contract IByocRegistryData {
event ContractPublished(
address indexed operator,
address indexed publisher,
IByocRegistry.CustomContractInstance publishedContract
IContractPublisher.CustomContractInstance publishedContract
);

/// @dev Emitted when a contract is unpublished.
Expand All @@ -42,8 +42,8 @@ contract IByocRegistryData {
event RemovedContractToPublicList(address indexed publisher, string indexed contractId);
}

contract ByocRegistryTest is BaseTest, IByocRegistryData {
ByocRegistry internal byoc;
contract ContractPublisherTest is BaseTest, IContractPublisherData {
ContractPublisher internal byoc;
TWRegistry internal twRegistry;

address internal publisher;
Expand All @@ -55,7 +55,7 @@ contract ByocRegistryTest is BaseTest, IByocRegistryData {
function setUp() public override {
super.setUp();

byoc = ByocRegistry(byocRegistry);
byoc = ContractPublisher(contractPublisher);
twRegistry = TWRegistry(registry);

publisher = getActor(0);
Expand All @@ -74,7 +74,10 @@ contract ByocRegistryTest is BaseTest, IByocRegistryData {
contractId
);

IByocRegistry.CustomContractInstance memory customContract = byoc.getPublishedContract(publisher, contractId);
IContractPublisher.CustomContractInstance memory customContract = byoc.getPublishedContract(
publisher,
contractId
);

assertEq(customContract.contractId, contractId);
assertEq(customContract.publishMetadataUri, publishMetadataUri);
Expand All @@ -97,7 +100,10 @@ contract ByocRegistryTest is BaseTest, IByocRegistryData {
contractId
);

IByocRegistry.CustomContractInstance memory customContract = byoc.getPublishedContract(publisher, contractId);
IContractPublisher.CustomContractInstance memory customContract = byoc.getPublishedContract(
publisher,
contractId
);

assertEq(customContract.contractId, contractId);
assertEq(customContract.publishMetadataUri, publishMetadataUri);
Expand Down Expand Up @@ -144,13 +150,14 @@ contract ByocRegistryTest is BaseTest, IByocRegistryData {
vm.prank(publisher);
byoc.approveOperator(operator, true);

IByocRegistry.CustomContractInstance memory expectedCustomContract = IByocRegistry.CustomContractInstance({
contractId: contractId,
publishTimestamp: 100,
publishMetadataUri: publishMetadataUri,
bytecodeHash: keccak256(type(MockCustomContract).creationCode),
implementation: address(0)
});
IContractPublisher.CustomContractInstance memory expectedCustomContract = IContractPublisher
.CustomContractInstance({
contractId: contractId,
publishTimestamp: 100,
publishMetadataUri: publishMetadataUri,
bytecodeHash: keccak256(type(MockCustomContract).creationCode),
implementation: address(0)
});

vm.expectEmit(true, true, true, true);
emit ContractPublished(operator, publisher, expectedCustomContract);
Expand Down Expand Up @@ -181,7 +188,10 @@ contract ByocRegistryTest is BaseTest, IByocRegistryData {
vm.prank(publisher);
byoc.unpublishContract(publisher, contractId);

IByocRegistry.CustomContractInstance memory customContract = byoc.getPublishedContract(publisher, contractId);
IContractPublisher.CustomContractInstance memory customContract = byoc.getPublishedContract(
publisher,
contractId
);

assertEq(customContract.contractId, "");
assertEq(customContract.publishMetadataUri, "");
Expand All @@ -207,7 +217,10 @@ contract ByocRegistryTest is BaseTest, IByocRegistryData {
vm.prank(operator);
byoc.unpublishContract(publisher, contractId);

IByocRegistry.CustomContractInstance memory customContract = byoc.getPublishedContract(publisher, contractId);
IContractPublisher.CustomContractInstance memory customContract = byoc.getPublishedContract(
publisher,
contractId
);

assertEq(customContract.contractId, "");
assertEq(customContract.publishMetadataUri, "");
Expand Down
10 changes: 5 additions & 5 deletions src/test/utils/BaseTest.sol
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@ import "contracts/token/TokenERC721.sol";
import "contracts/token/TokenERC1155.sol";
import "contracts/marketplace/Marketplace.sol";
import "contracts/vote/VoteERC20.sol";
import { ByocRegistry } from "contracts/ByocRegistry.sol";
import { ByocFactory } from "contracts/ByocFactory.sol";
import { ContractPublisher } from "contracts/ContractPublisher.sol";
import { ContractDeployer } from "contracts/ContractDeployer.sol";
import "contracts/mock/Mock.sol";

abstract contract BaseTest is DSTest, Test {
Expand All @@ -43,7 +43,7 @@ abstract contract BaseTest is DSTest, Test {
address public registry;
address public factory;
address public fee;
address public byocRegistry;
address public contractPublisher;

address public factoryAdmin = address(0x10000);
address public deployer = address(0x20000);
Expand All @@ -66,9 +66,9 @@ abstract contract BaseTest is DSTest, Test {
forwarder = address(new Forwarder());
registry = address(new TWRegistry(forwarder));
factory = address(new TWFactory(forwarder, registry));
byocRegistry = address(new ByocRegistry(forwarder));
contractPublisher = address(new ContractPublisher(forwarder));
TWRegistry(registry).grantRole(TWRegistry(registry).OPERATOR_ROLE(), factory);
TWRegistry(registry).grantRole(TWRegistry(registry).OPERATOR_ROLE(), byocRegistry);
TWRegistry(registry).grantRole(TWRegistry(registry).OPERATOR_ROLE(), contractPublisher);
fee = address(new TWFee(forwarder, factory));
TWFactory(factory).addImplementation(address(new TokenERC20(fee)));
TWFactory(factory).addImplementation(address(new TokenERC721(fee)));
Expand Down

0 comments on commit a603d4a

Please sign in to comment.