-
Notifications
You must be signed in to change notification settings - Fork 11.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
…5422) Co-authored-by: Ernesto García <[email protected]>
- Loading branch information
1 parent
7b74442
commit 352ab13
Showing
4 changed files
with
54 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
"openzeppelin-solidity": minor | ||
--- | ||
|
||
`Calldata`: Library with `emptyBytes` and `emptyString` functions to generate empty `bytes` and `string` calldata types. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
// SPDX-License-Identifier: MIT | ||
|
||
pragma solidity ^0.8.20; | ||
|
||
/** | ||
* @dev Helper library for manipulating objects in calldata. | ||
*/ | ||
library Calldata { | ||
// slither-disable-next-line write-after-write | ||
function emptyBytes() internal pure returns (bytes calldata result) { | ||
assembly ("memory-safe") { | ||
result.offset := 0 | ||
result.length := 0 | ||
} | ||
} | ||
|
||
// slither-disable-next-line write-after-write | ||
function emptyString() internal pure returns (string calldata result) { | ||
assembly ("memory-safe") { | ||
result.offset := 0 | ||
result.length := 0 | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
const { ethers } = require('hardhat'); | ||
const { expect } = require('chai'); | ||
const { loadFixture } = require('@nomicfoundation/hardhat-network-helpers'); | ||
|
||
async function fixture() { | ||
const mock = await ethers.deployContract('$Calldata'); | ||
return { mock }; | ||
} | ||
|
||
describe('Calldata utilities', function () { | ||
beforeEach(async function () { | ||
Object.assign(this, await loadFixture(fixture)); | ||
}); | ||
|
||
it('emptyBytes', async function () { | ||
await expect(this.mock.$emptyBytes()).to.eventually.equal('0x'); | ||
}); | ||
|
||
it('emptyString', async function () { | ||
await expect(this.mock.$emptyString()).to.eventually.equal(''); | ||
}); | ||
}); |