Skip to content

Commit

Permalink
refactor: pr comments
Browse files Browse the repository at this point in the history
  • Loading branch information
franciscotobar committed Feb 13, 2024
1 parent ff5b4db commit 5f16456
Show file tree
Hide file tree
Showing 6 changed files with 68 additions and 67 deletions.
14 changes: 7 additions & 7 deletions contracts/smartwallet/MinimalBoltzSmartWallet.sol
Original file line number Diff line number Diff line change
Expand Up @@ -14,16 +14,16 @@ contract MinimalBoltzSmartWallet {
* This function can only be called once, and it is called by the Factory during deployment
* @param owner - The EOA that will own the smart wallet
* @param feesReceiver - Recipient of payment
* @param tokenAmount - Amount to pay
* @param tokenGas - Gas limit of payment
* @param feesAmount - Amount to pay
* @param feesGas - Gas limit of payment
* @param to - Destination contract to execute
* @param data - Data to be execute by destination contract
*/
function initialize(
address owner,
address feesReceiver,
uint256 tokenAmount,
uint256 tokenGas,
uint256 feesAmount,
uint256 feesGas,
address to,
bytes calldata data
) external returns (bool success, bytes memory ret) {
Expand All @@ -42,10 +42,10 @@ contract MinimalBoltzSmartWallet {
}

//we need to initialize the contract
if (tokenAmount > 0) {
if (feesAmount > 0) {
(success, ret) = payable(feesReceiver).call{
value: tokenAmount,
gas: tokenGas
value: feesAmount,
gas: feesGas
}("");
require(
success && (ret.length == 0 || abi.decode(ret, (bool))),
Expand Down
4 changes: 2 additions & 2 deletions contracts/verifier/MinimalBoltzDeployVerifier.sol
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ pragma experimental ABIEncoderV2;

import "@openzeppelin/contracts/token/ERC20/IERC20.sol";

import "../factory/BoltzSmartWalletFactory.sol";
import "../factory/MinimalBoltzSmartWalletFactory.sol";
import "../interfaces/IDeployVerifier.sol";
import "../interfaces/EnvelopingTypes.sol";
import "../interfaces/BoltzVerifier.sol";
Expand Down Expand Up @@ -40,7 +40,7 @@ contract MinimalBoltzDeployVerifier is IDeployVerifier {
"Invalid factory"
);

address contractAddr = BoltzSmartWalletFactory(
address contractAddr = MinimalBoltzSmartWalletFactory(
relayRequest.relayData.callForwarder
).getSmartWalletAddress(
relayRequest.request.from,
Expand Down
43 changes: 0 additions & 43 deletions test/factory/minimalBoltzSmartWalletFactory.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -212,49 +212,6 @@ describe('MinimalBoltzSmartWalletFactory', function () {
expect(finalReceiverBalance).to.be.equal(initialReceiverBalance);
});

it('should fail when the smart wallet does not have funds to pay using token', async function () {
const amountToPay = utils.parseEther('6').toString();

const deployRequest = createDeployRequest(
{
from: owner.address,
tokenContract: ZERO_ADDRESS,
tokenAmount: amountToPay,
tokenGas,
recoverer: recoverer,
index: index,
relayHub: worker.address,
},
{
callForwarder: boltzSmartWalletFactory.address,
}
);

const { suffixData, signature } = signDeployRequest(
owner,
deployRequest,
boltzSmartWalletFactory.address,
chainId
);

const initialReceiverBalance = await feesReceiver.getBalance();

await expect(
boltzSmartWalletFactory
.connect(worker)
.relayedUserSmartWalletCreation(
deployRequest.request,
suffixData,
feesReceiver.address,
signature
)
).to.be.rejectedWith('Unable to pay for deployment');

const finalReceiverBalance = await feesReceiver.getBalance();

expect(finalReceiverBalance).to.be.equal(initialReceiverBalance);
});

it('should fail when the smart wallet does not have funds to pay using native', async function () {
const amountToPay = utils.parseEther('6').toString();

Expand Down
46 changes: 46 additions & 0 deletions test/smartwallet/minimalBoltzSmartWallet.template.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
import { MockContract, smock } from '@defi-wonderland/smock';
import {
MinimalBoltzSmartWallet,
MinimalBoltzSmartWallet__factory,
} from 'typechain-types';
import chai, { expect } from 'chai';
import chaiAsPromised from 'chai-as-promised';
import { ethers as hardhat } from 'hardhat';
import { SignerWithAddress } from '@nomiclabs/hardhat-ethers/signers';

chai.use(smock.matchers);
chai.use(chaiAsPromised);

const ZERO_ADDRESS = hardhat.constants.AddressZero;

describe('MinimalBoltzSmartWallet template', function () {
describe('Function initialize()', function () {
let smartWalletMock: MockContract<MinimalBoltzSmartWallet>;

beforeEach(async function () {
const smartWalletFactoryMock =
await smock.mock<MinimalBoltzSmartWallet__factory>(
'MinimalBoltzSmartWallet'
);

smartWalletMock = await smartWalletFactoryMock.deploy();
});

it('Should fail to initialize if alredy initialized', async function () {
const [owner] = (await hardhat.getSigners()) as [SignerWithAddress];
await smartWalletMock.setVariables({
_isInitialized: true,
});
await expect(
smartWalletMock.initialize(
owner.address,
ZERO_ADDRESS,
'0',
'0',
ZERO_ADDRESS,
'0x00'
)
).to.be.rejectedWith('Already initialized');
});
});
});
6 changes: 2 additions & 4 deletions test/smartwallet/smartWallet.template.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ describe('SmartWallet template', function () {

beforeEach(async function () {
const smartWalletFactoryMock = await smock.mock<SmartWallet__factory>(
'CustomSmartWallet'
'SmartWallet'
);

smartWalletMock = await smartWalletFactoryMock.deploy();
Expand All @@ -33,10 +33,8 @@ describe('SmartWallet template', function () {
owner.address,
ZERO_ADDRESS,
ZERO_ADDRESS,
ZERO_ADDRESS,
'0',
'50000',
'0x'
'50000'
)
).to.be.rejectedWith('Already initialized');
});
Expand Down
22 changes: 11 additions & 11 deletions test/verifier/minimalBoltzDeployVerifier.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ describe('MinimalBoltzDeployVerifier Contract', function () {
await expect(result).to.not.be.reverted;
});

it('should revert if paying with ERC20 token', async function () {
it('should not revert if not paying', async function () {
await deployVerifierMock.setVariables({
_factory: fakeWalletFactory.address,
});
Expand All @@ -139,10 +139,10 @@ describe('MinimalBoltzDeployVerifier Contract', function () {
from: owner.address,
to: recipient.address,
nonce: '0',
tokenGas: '50000',
tokenGas: '0',
relayHub: fakeRelayHub.address,
tokenAmount: '100000000000',
tokenContract: fakeToken.address,
tokenAmount: '0',
tokenContract: constants.AddressZero,
validUntilTime: '0',
value: '0',
},
Expand All @@ -152,10 +152,11 @@ describe('MinimalBoltzDeployVerifier Contract', function () {
deployRequest,
'0x00'
);
await expect(result).to.be.rejectedWith('RBTC necessary for payment');

await expect(result).to.not.be.reverted;
});

it('should not revert if not paying', async function () {
it('should revert if paying with ERC20 token', async function () {
await deployVerifierMock.setVariables({
_factory: fakeWalletFactory.address,
});
Expand All @@ -174,10 +175,10 @@ describe('MinimalBoltzDeployVerifier Contract', function () {
from: owner.address,
to: recipient.address,
nonce: '0',
tokenGas: '0',
tokenGas: '50000',
relayHub: fakeRelayHub.address,
tokenAmount: '0',
tokenContract: constants.AddressZero,
tokenAmount: '100000000000',
tokenContract: fakeToken.address,
validUntilTime: '0',
value: '0',
},
Expand All @@ -187,8 +188,7 @@ describe('MinimalBoltzDeployVerifier Contract', function () {
deployRequest,
'0x00'
);

await expect(result).to.not.be.reverted;
await expect(result).to.be.rejectedWith('RBTC necessary for payment');
});

it('should revert if factory address in request is different than factory address in contract', async function () {
Expand Down

0 comments on commit 5f16456

Please sign in to comment.