Skip to content

Commit

Permalink
Update ReceiptFactoryTest and use new logic in testInitialize
Browse files Browse the repository at this point in the history
  • Loading branch information
ninokeldishvili committed Oct 31, 2024
1 parent 4c9304d commit 8c4b763
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 13 deletions.
13 changes: 5 additions & 8 deletions test/abstract/ReceiptFactoryTest.sol
Original file line number Diff line number Diff line change
Expand Up @@ -7,24 +7,21 @@ import {CloneFactory} from "rain.factory/concrete/CloneFactory.sol";
import {TestReceipt} from "test/concrete/TestReceipt.sol";
import {Test, Vm} from "forge-std/Test.sol";
import {Receipt as ReceiptContract} from "src/concrete/receipt/Receipt.sol";
import {LibReceiptCreator} from "test/lib/LibReceiptCreator.sol";

contract ReceiptFactoryTest is Test {
ICloneableFactoryV2 internal immutable iFactory;
ReceiptContract internal immutable receiptImplementation;

constructor(address factoryAddress) {
iFactory = ICloneableFactoryV2(factoryAddress);
constructor() {
iFactory = new CloneFactory();
receiptImplementation = new ReceiptContract();
}

/// @notice Creates a new TestReceipt clone with the specified owner
/// @param owner The address to set as the owner of the new TestReceipt
/// @return The address of the newly created TestReceipt clone
function createReceipt(address owner) external returns (TestReceipt) {
// Clone TestReceipt using the factory and initialize it with the owner
address clone = iFactory.clone(address(receiptImplementation), abi.encode(owner));

// Return the clone cast to TestReceipt type
return TestReceipt(clone);
function createReceipt(address owner) internal returns (TestReceipt) {
return LibReceiptCreator.createReceipt(iFactory, receiptImplementation, owner);
}
}
8 changes: 3 additions & 5 deletions test/src/concrete/receipt/Receipt.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -2,21 +2,19 @@
// SPDX-FileCopyrightText: Copyright (c) 2020 thedavidmeister
pragma solidity ^0.8.25;

import {Test, Vm} from "forge-std/Test.sol";
import {Receipt} from "src/concrete/receipt/Receipt.sol";
import {IReceiptOwnerV1} from "src/interface/IReceiptOwnerV1.sol";
import {TestReceipt} from "test/concrete/TestReceipt.sol";
import {TestReceiptOwner} from "test/concrete/TestReceiptOwner.sol";
import {LibUniqueAddressesGenerator} from "../../../lib/LibUniqueAddressesGenerator.sol";
import {ReceiptFactoryTest, Vm} from "test/abstract/ReceiptFactoryTest.sol";

contract ReceiptTest is Test {
contract ReceiptTest is ReceiptFactoryTest {
event ReceiptInformation(address sender, uint256 id, bytes information);

function testInitialize() public {
TestReceipt receipt = new TestReceipt();
TestReceiptOwner mockOwner = new TestReceiptOwner();

receipt.setOwner(address(mockOwner));
TestReceipt receipt = createReceipt(address(mockOwner));
assertEq(receipt.owner(), address(mockOwner));
}

Expand Down

0 comments on commit 8c4b763

Please sign in to comment.