11import { ethers } from "hardhat" ;
22import { loadFixture } from "@nomicfoundation/hardhat-network-helpers" ;
33import faker from "faker" ;
4- import { ContractTransaction , Signer } from "ethers" ;
5- import { DummyContractMock , TitleEscrow , TitleEscrowFactory } from "@tradetrust/contracts" ;
4+ import { ContractTransaction } from "ethers" ;
5+ import { TitleEscrow , TitleEscrowFactory , TitleEscrowFactoryCallerMock } from "@tradetrust/contracts" ;
66import { TitleEscrowCreatedEvent } from "@tradetrust/contracts/contracts/TitleEscrowFactory" ;
77import { expect } from "." ;
88import { deployEscrowFactoryFixture } from "./fixtures" ;
99import { computeTitleEscrowAddress , getEventFromReceipt } from "../src/utils" ;
1010import { contractInterfaceId , defaultAddress } from "../src/constants" ;
11- import { createDeployFixtureRunner , getTestUsers , impersonateAccount , TestUsers } from "./helpers" ;
11+ import { createDeployFixtureRunner , getTestUsers , TestUsers } from "./helpers" ;
1212
1313describe ( "TitleEscrowFactory" , async ( ) => {
1414 let users : TestUsers ;
@@ -85,9 +85,14 @@ describe("TitleEscrowFactory", async () => {
8585
8686 describe ( "Create Title Escrow Contract" , ( ) => {
8787 let tokenId : string ;
88+ let titleEscrowFactoryCallerMock : TitleEscrowFactoryCallerMock ;
8889
8990 beforeEach ( async ( ) => {
9091 tokenId = faker . datatype . hexaDecimal ( 64 ) ;
92+
93+ titleEscrowFactoryCallerMock = ( await (
94+ await ethers . getContractFactory ( "TitleEscrowFactoryCallerMock" )
95+ ) . deploy ( ) ) as TitleEscrowFactoryCallerMock ;
9196 } ) ;
9297
9398 describe ( "Create Caller" , ( ) => {
@@ -100,33 +105,29 @@ describe("TitleEscrowFactory", async () => {
100105 } ) ;
101106
102107 it ( "should call create successfully from a contract" , async ( ) => {
103- const dummyContractMock = ( await (
104- await ethers . getContractFactory ( "DummyContractMock" )
105- ) . deploy ( ) ) as DummyContractMock ;
106- const mockContractSigner = await impersonateAccount ( { address : dummyContractMock . address } ) ;
107-
108- const tx = titleEscrowFactory . connect ( mockContractSigner ) . create ( tokenId ) ;
108+ const tx = titleEscrowFactoryCallerMock . connect ( users . carrier ) . callCreate ( titleEscrowFactory . address , tokenId ) ;
109109
110110 await expect ( tx ) . to . not . be . reverted ;
111111 } ) ;
112112 } ) ;
113113
114114 describe ( "Create Title Escrow Behaviours" , ( ) => {
115- let mockContractSigner : Signer ;
116115 let titleEscrowFactoryCreateTx : ContractTransaction ;
117116 let titleEscrowContract : TitleEscrow ;
118117
119118 beforeEach ( async ( ) => {
120- const dummyContractMock = ( await (
121- await ethers . getContractFactory ( "DummyContractMock" )
122- ) . deploy ( ) ) as DummyContractMock ;
123- mockContractSigner = await impersonateAccount ( { address : dummyContractMock . address } ) ;
124- titleEscrowFactoryCreateTx = await titleEscrowFactory . connect ( mockContractSigner ) . create ( tokenId ) ;
119+ const signer = users . others [ faker . datatype . number ( users . others . length - 1 ) ] ;
120+ titleEscrowFactoryCreateTx = await titleEscrowFactoryCallerMock
121+ . connect ( signer )
122+ . callCreate ( titleEscrowFactory . address , tokenId ) ;
125123
126124 const receipt = await titleEscrowFactoryCreateTx . wait ( ) ;
125+
126+ const titleEscrowFactoryInterface = ( await ethers . getContractFactory ( "TitleEscrowFactory" ) ) . interface ;
127127 const titleEscrowAddress = getEventFromReceipt < TitleEscrowCreatedEvent > (
128128 receipt ,
129- titleEscrowFactory . interface . getEventTopic ( "TitleEscrowCreated" )
129+ titleEscrowFactory . interface . getEventTopic ( "TitleEscrowCreated" ) ,
130+ titleEscrowFactoryInterface
130131 ) . args . titleEscrow ;
131132
132133 titleEscrowContract = ( await ethers . getContractFactory ( "TitleEscrow" ) ) . attach (
@@ -136,17 +137,17 @@ describe("TitleEscrowFactory", async () => {
136137
137138 it ( "should create with the correct token registry address" , async ( ) => {
138139 const registryAddress = await titleEscrowContract . registry ( ) ;
139- const signerAddress = await mockContractSigner . getAddress ( ) ;
140+ const createCallerAddress = titleEscrowFactoryCallerMock . address ;
140141
141- expect ( registryAddress ) . to . equal ( signerAddress ) ;
142+ expect ( registryAddress ) . to . equal ( createCallerAddress ) ;
142143 } ) ;
143144
144145 it ( "should emit TitleEscrowCreated event" , async ( ) => {
145- const signerAddress = await mockContractSigner . getAddress ( ) ;
146+ const createCallerAddress = titleEscrowFactoryCallerMock . address ;
146147
147148 expect ( titleEscrowFactoryCreateTx )
148149 . to . emit ( titleEscrowFactory , "TitleEscrowCreated" )
149- . withArgs ( titleEscrowContract . address , signerAddress , tokenId ) ;
150+ . withArgs ( titleEscrowContract . address , createCallerAddress , tokenId ) ;
150151 } ) ;
151152 } ) ;
152153 } ) ;
0 commit comments