Skip to content

Commit

Permalink
Fix integration tests
Browse files Browse the repository at this point in the history
  • Loading branch information
SoraSuegami committed Aug 6, 2024
1 parent 7d0b967 commit 04d8c18
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 21 deletions.
54 changes: 36 additions & 18 deletions packages/contracts/test/Integration.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,8 @@ contract IntegrationTest is IntegrationTestHelper {
user1.emailAddr,
user1.accountCode,
relayer1Rand,
"gmail.com"
"gmail.com",
"Send 0.12 ETH to "
);
vm.stopPrank();

Expand All @@ -49,7 +50,8 @@ contract IntegrationTest is IntegrationTestHelper {
user2.emailAddr,
user2.accountCode,
relayer1Rand,
"gmail.com"
"gmail.com",
"Send 0.12 ETH to "
);
vm.stopPrank();
}
Expand All @@ -61,7 +63,8 @@ contract IntegrationTest is IntegrationTestHelper {
user1.emailAddr,
user1.accountCode,
relayer1Rand,
"gmail.com"
"gmail.com",
"Send 0.12 ETH to "
);
address user1Wallet = address(user1WalletContract);
vm.stopPrank();
Expand Down Expand Up @@ -100,7 +103,8 @@ contract IntegrationTest is IntegrationTestHelper {
user2.emailAddr,
user2.accountCode,
relayer1Rand,
"gmail.com"
"gmail.com",
"Send 0.12 ETH to "
);
address user2Wallet = address(user2WalletContract);
console.logString("Relayer1 address: ");
Expand All @@ -123,7 +127,8 @@ contract IntegrationTest is IntegrationTestHelper {
user1.emailAddr,
user1.accountCode,
relayer1Rand,
"gmail.com"
"gmail.com",
"Send 0.12 ETH to "
);
address user1Wallet = address(user1WalletContract);
vm.stopPrank();
Expand All @@ -146,10 +151,11 @@ contract IntegrationTest is IntegrationTestHelper {
emailOp.walletParams.tokenName = "ETH";
emailOp.walletParams.amount = 0.25 ether;
emailOp.recipientETHAddr = recipient;
uint recipientPreBalance = recipient.balance;
(bool success, bytes memory reason, , ) = core.handleEmailOp{value: 0}(emailOp);
assertEq(success, true, string(reason));
require(weth.balanceOf(user1Wallet) < 0.05 ether, "User1 wallet balance is too large");
require(recipient.balance == 0.25 ether, "Recipient address balance mismatch");
require(recipient.balance - recipientPreBalance == 0.25 ether, "Recipient address balance mismatch");
require(weth.balanceOf(address(unclaimsHandler)) == 0, "Core contract balance mismatch");
vm.stopPrank();
}
Expand All @@ -161,7 +167,8 @@ contract IntegrationTest is IntegrationTestHelper {
user1.emailAddr,
user1.accountCode,
relayer1Rand,
"gmail.com"
"gmail.com",
"Send 0.12 ETH to "
);
address user1Wallet = address(user1WalletContract);
vm.stopPrank();
Expand All @@ -172,7 +179,8 @@ contract IntegrationTest is IntegrationTestHelper {
user2.emailAddr,
user2.accountCode,
relayer1Rand,
"gmail.com"
"gmail.com",
"Send 0.12 ETH to "
);
address user2Wallet = address(user2WalletContract);
vm.stopPrank();
Expand Down Expand Up @@ -271,7 +279,8 @@ contract IntegrationTest is IntegrationTestHelper {
user1.emailAddr,
user1.accountCode,
relayer1Rand,
"gmail.com"
"gmail.com",
"Send 0.12 ETH to "
);
address user1Wallet = address(user1WalletContract);
vm.stopPrank();
Expand Down Expand Up @@ -459,7 +468,8 @@ contract IntegrationTest is IntegrationTestHelper {
user1.emailAddr,
user1.accountCode,
relayer1Rand,
"gmail.com"
"gmail.com",
"Send 0.12 ETH to "
);
address user1Wallet = address(user1WalletContract);
claimFund(registeredUnclaimId, user1.emailAddr, rand1, user1.accountCode);
Expand Down Expand Up @@ -501,13 +511,14 @@ contract IntegrationTest is IntegrationTestHelper {
emailOp.walletParams.tokenName = "ETH";
emailOp.walletParams.amount = 0.25 ether;
emailOp.recipientETHAddr = recipient;
uint recipientPreBalance = recipient.balance;
(success, reason, , ) = core.handleEmailOp{value: 0}(emailOp);
assertEq(success, true, string(reason));
require(
weth.balanceOf(user1Wallet) < 0.15 ether,
"User1 wallet balance after the second transaction is too large"
);
require(recipient.balance == 0.25 ether, "Recipient eth balance mismatch");
require(recipient.balance - recipientPreBalance == 0.25 ether, "Recipient eth balance mismatch");
require(weth.balanceOf(recipient) == 0, "Recipient weth balance must be zero");
vm.stopPrank();
}
Expand All @@ -519,7 +530,8 @@ contract IntegrationTest is IntegrationTestHelper {
user1.emailAddr,
user1.accountCode,
relayer1Rand,
"gmail.com"
"gmail.com",
"Send 0.12 ETH to "
);
address user1Wallet = address(user1WalletContract);
vm.stopPrank();
Expand Down Expand Up @@ -578,7 +590,8 @@ contract IntegrationTest is IntegrationTestHelper {
user1.emailAddr,
user1.accountCode,
relayer1Rand,
"gmail.com"
"gmail.com",
"Send 0.12 ETH to "
);
address user1Wallet = address(user1WalletContract);
vm.stopPrank();
Expand Down Expand Up @@ -634,7 +647,8 @@ contract IntegrationTest is IntegrationTestHelper {
user2.emailAddr,
user2.accountCode,
relayer1Rand,
"gmail.com"
"gmail.com",
"Send 0.12 ETH to "
);
address user2Wallet = address(user2WalletContract);
vm.stopPrank();
Expand All @@ -652,7 +666,8 @@ contract IntegrationTest is IntegrationTestHelper {
user1.emailAddr,
user1.accountCode,
relayer1Rand,
"gmail.com"
"gmail.com",
"Send 0.12 ETH to "
);
address user1Wallet = address(user1WalletContract);
vm.stopPrank();
Expand Down Expand Up @@ -742,7 +757,8 @@ contract IntegrationTest is IntegrationTestHelper {
user1.emailAddr,
user1.accountCode,
relayer1Rand,
"gmail.com"
"gmail.com",
"Send 0.12 ETH to "
);
address user1Wallet = address(user1WalletContract);
vm.stopPrank();
Expand All @@ -760,7 +776,8 @@ contract IntegrationTest is IntegrationTestHelper {
user1.emailAddr,
user1.accountCode,
relayer1Rand,
"gmail.com"
"gmail.com",
"Send 0.12 ETH to "
);
address user1Wallet = address(user1WalletContract);
vm.stopPrank();
Expand Down Expand Up @@ -830,7 +847,8 @@ contract IntegrationTest is IntegrationTestHelper {
user1.emailAddr,
user1.accountCode,
relayer1Rand,
"gmail.com"
"gmail.com",
"Send 0.12 ETH to "
);
address user1Wallet = address(user1WalletContract);
vm.stopPrank();
Expand Down
2 changes: 1 addition & 1 deletion packages/contracts/test/bin/claim.sh
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ INPUT_FILE="${SCRIPT_DIR}/../build_integration/claim_input.json"
yarn workspace @email-wallet/circom gen-claim-input \
--email-addr $EMAIL_ADDR \
--email-addr-rand $EMAIL_ADDR_RAND \
--account-key $ACCOUNT_CODE \
--account-code $ACCOUNT_CODE \
--input-file $INPUT_FILE \
--prove
exit 0
5 changes: 3 additions & 2 deletions packages/contracts/test/helpers/IntegrationTestHelper.sol
Original file line number Diff line number Diff line change
Expand Up @@ -279,10 +279,11 @@ abstract contract IntegrationTestHelper is Test {
string memory emailAddr,
bytes32 accountCode,
bytes32 relayerRand,
string memory emailDomain
string memory emailDomain,
string memory maskedSubject
) internal returns (Wallet wallet) {
EmailProof memory emailProof;
(emailProof, ) = genEmailProof(emailFile, accountCode, emailDomain, emailAddr);
(emailProof, ) = genEmailProof(emailFile, accountCode, emailDomain, maskedSubject);

string memory projectRoot = vm.projectRoot();
string[] memory inputGenerationInput = new string[](4);
Expand Down

0 comments on commit 04d8c18

Please sign in to comment.