Skip to content

Commit

Permalink
refactor: pr comments
Browse files Browse the repository at this point in the history
  • Loading branch information
franciscotobar committed Mar 28, 2023
1 parent 9de815a commit 3898456
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 22 deletions.
25 changes: 15 additions & 10 deletions test/factory/customSmartWalletFactory.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,7 @@ describe('CustomSmartWalletFactory', function () {
smartWalletAddress
);

expect(smartWallet.address).to.be.equal(smartWalletAddress);
await expect(smartWallet.isInitialized()).to.eventually.be.true;
});

Expand Down Expand Up @@ -200,8 +201,8 @@ describe('CustomSmartWalletFactory', function () {
let index: number;
let smartWalletAddress: string;
let worker: SignerWithAddress;
let otherCaller: SignerWithAddress;
let token: UtilToken;
const tokenGas = 55000;
let logicAddress: string;
const initParams = '0x';

Expand All @@ -217,12 +218,12 @@ describe('CustomSmartWalletFactory', function () {
utils.keccak256(initParams),
index
);
[worker, otherCaller] = await ethers.getSigners();
[worker] = await ethers.getSigners();
({ contract: token } = await deployContract<UtilToken, []>({
contractName: 'UtilToken',
constructorArgs: [],
}));
await token.mint(1000, smartWalletAddress);
await token.mint(utils.parseEther('5'), smartWalletAddress);
});

it('should initialize the smart wallet in the expected address without paying fee', async function () {
Expand Down Expand Up @@ -271,14 +272,14 @@ describe('CustomSmartWalletFactory', function () {
});

it('should initialize the smart wallet in the expected address paying fee', async function () {
const amountToPay = 500;
const amountToPay = utils.parseEther('2').toString();

const deployRequest = createDeployRequest(
{
from: owner.address,
tokenContract: token.address,
tokenAmount: amountToPay,
tokenGas: 55000,
tokenGas,
recoverer: recoverer,
index: index,
relayHub: worker.address,
Expand Down Expand Up @@ -320,7 +321,7 @@ describe('CustomSmartWalletFactory', function () {
});

it('should fail with tokenGas equals to zero while paying fee', async function () {
const amountToPay = 500;
const amountToPay = utils.parseEther('2').toString();

const deployRequest = createDeployRequest(
{
Expand Down Expand Up @@ -362,15 +363,15 @@ describe('CustomSmartWalletFactory', function () {
expect(finalWorkerBalance).to.be.equal(initialWorkerBalance);
});

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

const deployRequest = createDeployRequest(
{
from: owner.address,
tokenContract: token.address,
tokenAmount: amountToPay,
tokenGas: 55000,
tokenGas,
recoverer: recoverer,
index: index,
relayHub: worker.address,
Expand Down Expand Up @@ -430,9 +431,13 @@ describe('CustomSmartWalletFactory', function () {

const initialWorkerBalance = await token.balanceOf(worker.address);

const invalidRelayHub = (await ethers.getSigners()).at(
1
) as SignerWithAddress;

await expect(
customSmartWalletFactory
.connect(otherCaller)
.connect(invalidRelayHub)
.relayedUserSmartWalletCreation(
deployRequest.request,
suffixData,
Expand Down
29 changes: 17 additions & 12 deletions test/factory/smartWalletFactory.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,7 @@ describe('SmartWalletFactory', function () {
smartWalletAddress
);

expect(smartWallet.address).to.be.equal(smartWalletAddress);
await expect(smartWallet.isInitialized()).to.eventually.be.true;
});

Expand Down Expand Up @@ -171,8 +172,8 @@ describe('SmartWalletFactory', function () {
let index: number;
let smartWalletAddress: string;
let worker: SignerWithAddress;
let otherCaller: SignerWithAddress;
let token: UtilToken;
const tokenGas = 55000;

beforeEach(async function () {
recoverer = constants.AddressZero;
Expand All @@ -182,21 +183,21 @@ describe('SmartWalletFactory', function () {
recoverer,
index
);
[worker, otherCaller] = await ethers.getSigners();
[worker] = await ethers.getSigners();
({ contract: token } = await deployContract<UtilToken, []>({
contractName: 'UtilToken',
constructorArgs: [],
}));
await token.mint(1000, smartWalletAddress);
await token.mint(utils.parseEther('5'), smartWalletAddress);
});

it('should initialize the smart wallet in the expected address without paying fee', async function () {
const deployRequest = createDeployRequest(
{
from: owner.address,
tokenContract: token.address,
tokenAmount: '0',
tokenGas: '0',
tokenAmount: 0,
tokenGas: 0,
recoverer: recoverer,
index: index,
relayHub: worker.address,
Expand Down Expand Up @@ -236,14 +237,14 @@ describe('SmartWalletFactory', function () {
});

it('should initialize the smart wallet in the expected address paying fee', async function () {
const amountToPay = 500;
const amountToPay = utils.parseEther('2').toString();

const deployRequest = createDeployRequest(
{
from: owner.address,
tokenContract: token.address,
tokenAmount: amountToPay,
tokenGas: 55000,
tokenGas,
recoverer: recoverer,
index: index,
relayHub: worker.address,
Expand Down Expand Up @@ -285,7 +286,7 @@ describe('SmartWalletFactory', function () {
});

it('should fail with tokenGas equals to zero while paying fee', async function () {
const amountToPay = 500;
const amountToPay = utils.parseEther('2').toString();

const deployRequest = createDeployRequest(
{
Expand Down Expand Up @@ -327,15 +328,15 @@ describe('SmartWalletFactory', function () {
expect(finalWorkerBalance).to.be.equal(initialWorkerBalance);
});

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

const deployRequest = createDeployRequest(
{
from: owner.address,
tokenContract: token.address,
tokenAmount: amountToPay,
tokenGas: 55000,
tokenGas,
recoverer: recoverer,
index: index,
relayHub: worker.address,
Expand Down Expand Up @@ -395,9 +396,13 @@ describe('SmartWalletFactory', function () {

const initialWorkerBalance = await token.balanceOf(worker.address);

const invalidRelayHub = (await ethers.getSigners()).at(
1
) as SignerWithAddress;

await expect(
smartWalletFactory
.connect(otherCaller)
.connect(invalidRelayHub)
.relayedUserSmartWalletCreation(
deployRequest.request,
suffixData,
Expand Down

0 comments on commit 3898456

Please sign in to comment.