Skip to content

Commit

Permalink
Merge pull request #24 from bcnmy/fix/tests-accounting-stackdeep
Browse files Browse the repository at this point in the history
Fix/tests accounting stackdeep
  • Loading branch information
livingrockrises authored Oct 15, 2024
2 parents 4062a45 + c53a0ea commit 061b152
Show file tree
Hide file tree
Showing 25 changed files with 553 additions and 421 deletions.
21 changes: 16 additions & 5 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,18 @@ jobs:
- name: Checkout
uses: actions/checkout@v3

- name: Install pnpm
uses: pnpm/action-setup@v2
with:
version: 8

- name: Set up Node.js
uses: actions/setup-node@v4
with:
node-version: '22' # Specify the Node.js version you want to use

- name: Install dependencies
run: yarn cache clean && yarn install
run: pnpm install --ignore-scripts

- name: Install Foundry
uses: foundry-rs/foundry-toolchain@v1
Expand All @@ -25,7 +30,8 @@ jobs:
run: forge install

- name: Lint sources
run: yarn lint:sol
run: pnpm lint:sol
continue-on-error: true

unit_test:
name: Unit tests
Expand All @@ -34,8 +40,13 @@ jobs:
- name: Checkout
uses: actions/checkout@v3

- name: Install pnpm
uses: pnpm/action-setup@v2
with:
version: 8

- name: Install dependencies
run: yarn cache clean && yarn install
run: pnpm install --ignore-scripts

- name: Create a fake .secret file
run: echo "primary twist rack vendor diagram image used route theme frown either will" > .secret
Expand All @@ -49,7 +60,7 @@ jobs:
run: forge install

- name: Build Typechain and Foundry
run: yarn build
run: pnpm build

- name: Run Forge Tests
run: yarn test
run: pnpm test
9 changes: 7 additions & 2 deletions .github/workflows/coverage.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,11 @@ jobs:
- name: Checkout Repository
uses: actions/checkout@v3

- name: Install pnpm
uses: pnpm/action-setup@v2
with:
version: 8

- name: Set up Node.js
uses: actions/setup-node@v4
with:
Expand All @@ -16,7 +21,7 @@ jobs:
run: sudo apt-get update && sudo apt-get install -y lcov

- name: Install JavaScript Dependencies
run: yarn cache clean && yarn install
run: pnpm install --ignore-scripts

- name: Install Foundry
uses: foundry-rs/foundry-toolchain@v1
Expand All @@ -27,7 +32,7 @@ jobs:
run: forge install

- name: Generate Foundry Coverage Report
run: yarn coverage:report
run: pnpm coverage:report

- name: Upload Foundry Coverage Report to Codecov
uses: codecov/codecov-action@v3
Expand Down
1 change: 1 addition & 0 deletions .npmrc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
node-linker=hoisted
20 changes: 10 additions & 10 deletions contracts/base/BasePaymaster.sol
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,13 @@ import "account-abstraction/core/UserOperationLib.sol";
abstract contract BasePaymaster is IPaymaster, SoladyOwnable {
IEntryPoint public immutable entryPoint;

Check warning on line 18 in contracts/base/BasePaymaster.sol

View workflow job for this annotation

GitHub Actions / Lint sources

Immutable variables name are set to be in capitalized SNAKE_CASE

uint256 internal constant PAYMASTER_VALIDATION_GAS_OFFSET = UserOperationLib.PAYMASTER_VALIDATION_GAS_OFFSET;
uint256 internal constant PAYMASTER_POSTOP_GAS_OFFSET = UserOperationLib.PAYMASTER_POSTOP_GAS_OFFSET;
uint256 internal constant PAYMASTER_DATA_OFFSET = UserOperationLib.PAYMASTER_DATA_OFFSET;
uint256 internal constant _PAYMASTER_VALIDATION_GAS_OFFSET = UserOperationLib.PAYMASTER_VALIDATION_GAS_OFFSET;
uint256 internal constant _PAYMASTER_POSTOP_GAS_OFFSET = UserOperationLib.PAYMASTER_POSTOP_GAS_OFFSET;
uint256 internal constant _PAYMASTER_DATA_OFFSET = UserOperationLib.PAYMASTER_DATA_OFFSET;

constructor(address _owner, IEntryPoint _entryPoint) SoladyOwnable(_owner) {
_validateEntryPointInterface(_entryPoint);
entryPoint = _entryPoint;
constructor(address owner, IEntryPoint entryPointArg) SoladyOwnable(owner) {
_validateEntryPointInterface(entryPointArg);
entryPoint = entryPointArg;
}

/**
Expand Down Expand Up @@ -105,9 +105,9 @@ abstract contract BasePaymaster is IPaymaster, SoladyOwnable {

//sanity check: make sure this EntryPoint was compiled against the same
// IEntryPoint of this paymaster
function _validateEntryPointInterface(IEntryPoint _entryPoint) internal virtual {
function _validateEntryPointInterface(IEntryPoint entryPointArg) internal virtual {
require(

Check warning on line 109 in contracts/base/BasePaymaster.sol

View workflow job for this annotation

GitHub Actions / Lint sources

GC: Use Custom Errors instead of require statements
IERC165(address(_entryPoint)).supportsInterface(type(IEntryPoint).interfaceId),
IERC165(address(entryPointArg)).supportsInterface(type(IEntryPoint).interfaceId),
"IEntryPoint interface mismatch"
);
}
Expand Down Expand Up @@ -166,10 +166,10 @@ abstract contract BasePaymaster is IPaymaster, SoladyOwnable {
/**
* Check if address is a contract
*/
function _isContract(address _addr) internal view returns (bool) {
function _isContract(address addr) internal view returns (bool) {
uint256 size;
assembly ("memory-safe") {

Check warning on line 171 in contracts/base/BasePaymaster.sol

View workflow job for this annotation

GitHub Actions / Lint sources

Avoid to use inline assembly. It is acceptable only in rare cases
size := extcodesize(_addr)
size := extcodesize(addr)
}
return size > 0;
}
Expand Down
5 changes: 5 additions & 0 deletions contracts/common/BiconomySponsorshipPaymasterErrors.sol
Original file line number Diff line number Diff line change
Expand Up @@ -76,4 +76,9 @@ contract BiconomySponsorshipPaymasterErrors {
* @notice Throws when trying unaccountedGas is too high
*/
error UnaccountedGasTooHigh();

/**
* @notice Throws when postOp gas limit is too low
*/
error PostOpGasLimitTooLow();
}
10 changes: 6 additions & 4 deletions contracts/interfaces/IBiconomySponsorshipPaymaster.sol
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ pragma solidity ^0.8.27;
import "@openzeppelin/contracts/token/ERC20/IERC20.sol";

Check warning on line 4 in contracts/interfaces/IBiconomySponsorshipPaymaster.sol

View workflow job for this annotation

GitHub Actions / Lint sources

global import of path @openzeppelin/contracts/token/ERC20/IERC20.sol is not allowed. Specify names to import individually or bind all exports of the module into a name (import "path" as Name)
import { PackedUserOperation } from "account-abstraction/core/UserOperationLib.sol";

interface IBiconomySponsorshipPaymaster{
interface IBiconomySponsorshipPaymaster {
event UnaccountedGasChanged(uint256 indexed oldValue, uint256 indexed newValue);
event FixedPriceMarkupChanged(uint256 indexed oldValue, uint256 indexed newValue);
event VerifyingSignerChanged(address indexed oldSigner, address indexed newSigner, address indexed actor);
Expand All @@ -18,9 +18,9 @@ interface IBiconomySponsorshipPaymaster{

function depositFor(address paymasterId) external payable;

function setSigner(address _newVerifyingSigner) external payable;
function setSigner(address newVerifyingSigner) external payable;

function setFeeCollector(address _newFeeCollector) external payable;
function setFeeCollector(address newFeeCollector) external payable;

function setUnaccountedGas(uint256 value) external payable;

Expand All @@ -41,7 +41,9 @@ interface IBiconomySponsorshipPaymaster{
view
returns (bytes32);

function parsePaymasterAndData(bytes calldata paymasterAndData)
function parsePaymasterAndData(
bytes calldata paymasterAndData
)
external
pure
returns (
Expand Down
10 changes: 5 additions & 5 deletions contracts/interfaces/IBiconomyTokenPaymaster.sol
Original file line number Diff line number Diff line change
Expand Up @@ -38,15 +38,15 @@ interface IBiconomyTokenPaymaster {
event UpdatedTokenDirectory(address indexed tokenAddress, IOracle indexed oracle, uint8 decimals);
event UpdatedNativeAssetOracle(IOracle indexed oldOracle, IOracle indexed newOracle);

function setSigner(address _newVerifyingSigner) external payable;
function setSigner(address newVerifyingSigner) external payable;

function setUnaccountedGas(uint256 value) external payable;

function setPriceMarkup(uint256 _newUnaccountedGas) external payable;
function setPriceMarkup(uint256 newUnaccountedGas) external payable;

function setPriceExpiryDuration(uint256 _newPriceExpiryDuration) external payable;
function setPriceExpiryDuration(uint256 newPriceExpiryDuration) external payable;

function setNativeAssetToUsdOracle(IOracle _oracle) external payable;
function setNativeAssetToUsdOracle(IOracle oracle) external payable;

function updateTokenDirectory(address _tokenAddress, IOracle _oracle) external payable;
function updateTokenDirectory(address tokenAddress, IOracle oracle) external payable;
}
2 changes: 1 addition & 1 deletion contracts/interfaces/oracles/IOracle.sol
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,4 @@ interface IOracle {
external
view
returns (uint80 roundId, int256 answer, uint256 startedAt, uint256 updatedAt, uint80 answeredInRound);
}
}
12 changes: 9 additions & 3 deletions contracts/libraries/TokenPaymasterParserLib.sol
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,9 @@ library TokenPaymasterParserLib {
// Start offset of mode in PND
uint256 private constant PAYMASTER_MODE_OFFSET = UserOperationLib.PAYMASTER_DATA_OFFSET;

function parsePaymasterAndData(bytes calldata paymasterAndData)
function parsePaymasterAndData(
bytes calldata paymasterAndData
)
external
pure
returns (IBiconomyTokenPaymaster.PaymasterMode mode, bytes memory modeSpecificData)
Expand All @@ -20,7 +22,9 @@ library TokenPaymasterParserLib {
}
}

function parseExternalModeSpecificData(bytes calldata modeSpecificData)
function parseExternalModeSpecificData(
bytes calldata modeSpecificData
)
external
pure
returns (
Expand All @@ -40,7 +44,9 @@ library TokenPaymasterParserLib {
signature = modeSpecificData[52:];
}

function parseIndependentModeSpecificData(bytes calldata modeSpecificData)
function parseIndependentModeSpecificData(
bytes calldata modeSpecificData
)
external
pure
returns (address tokenAddress)
Expand Down
Loading

0 comments on commit 061b152

Please sign in to comment.