1
1
import { ethers } from "hardhat" ;
2
2
import { loadFixture } from "@nomicfoundation/hardhat-network-helpers" ;
3
3
import 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" ;
6
6
import { TitleEscrowCreatedEvent } from "@tradetrust/contracts/contracts/TitleEscrowFactory" ;
7
7
import { expect } from "." ;
8
8
import { deployEscrowFactoryFixture } from "./fixtures" ;
9
9
import { computeTitleEscrowAddress , getEventFromReceipt } from "../src/utils" ;
10
10
import { contractInterfaceId , defaultAddress } from "../src/constants" ;
11
- import { createDeployFixtureRunner , getTestUsers , impersonateAccount , TestUsers } from "./helpers" ;
11
+ import { createDeployFixtureRunner , getTestUsers , TestUsers } from "./helpers" ;
12
12
13
13
describe ( "TitleEscrowFactory" , async ( ) => {
14
14
let users : TestUsers ;
@@ -85,9 +85,14 @@ describe("TitleEscrowFactory", async () => {
85
85
86
86
describe ( "Create Title Escrow Contract" , ( ) => {
87
87
let tokenId : string ;
88
+ let titleEscrowFactoryCallerMock : TitleEscrowFactoryCallerMock ;
88
89
89
90
beforeEach ( async ( ) => {
90
91
tokenId = faker . datatype . hexaDecimal ( 64 ) ;
92
+
93
+ titleEscrowFactoryCallerMock = ( await (
94
+ await ethers . getContractFactory ( "TitleEscrowFactoryCallerMock" )
95
+ ) . deploy ( ) ) as TitleEscrowFactoryCallerMock ;
91
96
} ) ;
92
97
93
98
describe ( "Create Caller" , ( ) => {
@@ -100,33 +105,29 @@ describe("TitleEscrowFactory", async () => {
100
105
} ) ;
101
106
102
107
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 ) ;
109
109
110
110
await expect ( tx ) . to . not . be . reverted ;
111
111
} ) ;
112
112
} ) ;
113
113
114
114
describe ( "Create Title Escrow Behaviours" , ( ) => {
115
- let mockContractSigner : Signer ;
116
115
let titleEscrowFactoryCreateTx : ContractTransaction ;
117
116
let titleEscrowContract : TitleEscrow ;
118
117
119
118
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 ) ;
125
123
126
124
const receipt = await titleEscrowFactoryCreateTx . wait ( ) ;
125
+
126
+ const titleEscrowFactoryInterface = ( await ethers . getContractFactory ( "TitleEscrowFactory" ) ) . interface ;
127
127
const titleEscrowAddress = getEventFromReceipt < TitleEscrowCreatedEvent > (
128
128
receipt ,
129
- titleEscrowFactory . interface . getEventTopic ( "TitleEscrowCreated" )
129
+ titleEscrowFactory . interface . getEventTopic ( "TitleEscrowCreated" ) ,
130
+ titleEscrowFactoryInterface
130
131
) . args . titleEscrow ;
131
132
132
133
titleEscrowContract = ( await ethers . getContractFactory ( "TitleEscrow" ) ) . attach (
@@ -136,17 +137,17 @@ describe("TitleEscrowFactory", async () => {
136
137
137
138
it ( "should create with the correct token registry address" , async ( ) => {
138
139
const registryAddress = await titleEscrowContract . registry ( ) ;
139
- const signerAddress = await mockContractSigner . getAddress ( ) ;
140
+ const createCallerAddress = titleEscrowFactoryCallerMock . address ;
140
141
141
- expect ( registryAddress ) . to . equal ( signerAddress ) ;
142
+ expect ( registryAddress ) . to . equal ( createCallerAddress ) ;
142
143
} ) ;
143
144
144
145
it ( "should emit TitleEscrowCreated event" , async ( ) => {
145
- const signerAddress = await mockContractSigner . getAddress ( ) ;
146
+ const createCallerAddress = titleEscrowFactoryCallerMock . address ;
146
147
147
148
expect ( titleEscrowFactoryCreateTx )
148
149
. to . emit ( titleEscrowFactory , "TitleEscrowCreated" )
149
- . withArgs ( titleEscrowContract . address , signerAddress , tokenId ) ;
150
+ . withArgs ( titleEscrowContract . address , createCallerAddress , tokenId ) ;
150
151
} ) ;
151
152
} ) ;
152
153
} ) ;
0 commit comments