Skip to content

Commit ab88c0f

Browse files
committed
test return on faillure
1 parent 6a74179 commit ab88c0f

File tree

1 file changed

+42
-5
lines changed

1 file changed

+42
-5
lines changed

test/utils/LowLevelCall.test.js

Lines changed: 42 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -103,14 +103,34 @@ describe('LowLevelCall', function () {
103103
});
104104

105105
it('calls the requested function and returns false if the subcall reverts', async function () {
106-
const tx = this.mock.$callReturn64Bytes(
107-
this.target,
108-
this.target.interface.encodeFunctionData('mockFunctionRevertsNoReason'),
109-
);
110-
await expect(tx)
106+
await expect(
107+
this.mock.$callReturn64Bytes(
108+
this.target,
109+
this.target.interface.encodeFunctionData('mockFunctionRevertsNoReason'),
110+
),
111+
)
111112
.to.emit(this.mock, 'return$callReturn64Bytes_address_bytes')
112113
.withArgs(false, ethers.ZeroHash, ethers.ZeroHash);
113114
});
115+
116+
it('returns the first 64 bytes of the revert reason or custom error if the subcall reverts', async function () {
117+
const encoded = ethers.Interface.from(['error Error(string)']).encodeErrorResult('Error', [
118+
'CallReceiverMock: reverting',
119+
]);
120+
121+
await expect(
122+
this.mock.$callReturn64Bytes(
123+
this.target,
124+
this.target.interface.encodeFunctionData('mockFunctionRevertsReason'),
125+
),
126+
)
127+
.to.emit(this.mock, 'return$callReturn64Bytes_address_bytes')
128+
.withArgs(
129+
false,
130+
ethers.hexlify(ethers.getBytes(encoded).slice(0x00, 0x20)),
131+
ethers.hexlify(ethers.getBytes(encoded).slice(0x20, 0x40)),
132+
);
133+
});
114134
});
115135
});
116136

@@ -150,6 +170,23 @@ describe('LowLevelCall', function () {
150170
),
151171
).to.eventually.deep.equal([false, ethers.ZeroHash, ethers.ZeroHash]);
152172
});
173+
174+
it('returns the first 64 bytes of the revert reason or custom error if the subcall reverts', async function () {
175+
const encoded = ethers.Interface.from(['error Error(string)']).encodeErrorResult('Error', [
176+
'CallReceiverMock: reverting',
177+
]);
178+
179+
await expect(
180+
this.mock.$staticcallReturn64Bytes(
181+
this.target,
182+
this.target.interface.encodeFunctionData('mockFunctionRevertsReason'),
183+
),
184+
).to.eventually.deep.equal([
185+
false,
186+
ethers.hexlify(ethers.getBytes(encoded).slice(0x00, 0x20)),
187+
ethers.hexlify(ethers.getBytes(encoded).slice(0x20, 0x40)),
188+
]);
189+
});
153190
});
154191
});
155192

0 commit comments

Comments
 (0)