Skip to content

Commit dcd0ab2

Browse files
fix: contract periphery tests (#688)
* fix: explicitly sort the tokens by addr * fix: use vm.computeCreateAddress * fix: mirror test sender params * fix: use actual owner * fix: add back gnosis * Remove all reference to INFURA_ID (#687) --------- Co-authored-by: John Feras <[email protected]>
1 parent 5d63f2a commit dcd0ab2

13 files changed

+59
-39
lines changed

.github/workflows/ci.yaml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,6 @@ env:
2828
GNOSIS_CHAIN_RPC_URL: ${{ secrets.GNOSIS_CHAIN_RPC_URL }}
2929
BASE_RPC_URL: $${{ secrets.BASE_RPC_URL }}
3030
FOUNDRY_PROFILE: ci
31-
INFURA_ID: ${{ secrets.INFURA_ID }}
3231
WALLET_CONNECT_PROJECT_ID: ${{ secrets.WALLET_CONNECT_PROJECT_ID }}
3332

3433
jobs:

contracts-core/.env.example

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
INFURA_ID=zzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz
21
MNEMONIC=here is where your twelve words mnemonic should be put my friend
32
DEPLOY_GSN=false
43
ETHERSCAN_VERIFICATION_API_KEY="YOUR_API_KEY"

contracts-periphery/Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,4 +13,4 @@ install :; $(INSTALL_CMD)
1313
test :; forge test --sender 0x4f78F7f3482D9f1790649f9DD18Eec5A1Cc70F86 --no-match-contract ApproveBatchSendTokensTest
1414
test-gas :; forge test --match-path *.gas.t.sol
1515
snapshot-gas :; forge test --match-path *.gas.t.sol --gas-report > snapshot/.gas
16-
coverage :; forge coverage --report lcov --report summary && sed -i'.bak' 's/SF:/SF:contracts-periphery\//gI' lcov.info
16+
coverage :; forge coverage --sender 0x4f78F7f3482D9f1790649f9DD18Eec5A1Cc70F86 --report lcov --report summary && sed -i'.bak' 's/SF:/SF:contracts-periphery\//gI' lcov.info

contracts-periphery/script/ApproveBatchSendTokens.s.sol

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,12 @@ import {UmbraBatchSend} from "src/UmbraBatchSend.sol";
77

88
contract ApproveBatchSendTokens is Script {
99
function run(
10+
address _owner,
1011
address _umbraContractAddress,
1112
address _batchSendContractAddress,
1213
address[] calldata _tokenAddressesToApprove
1314
) public {
14-
vm.startBroadcast();
15+
vm.startBroadcast(_owner);
1516
for (uint256 _i = 0; _i < _tokenAddressesToApprove.length; _i++) {
1617
uint256 _currentAllowance = IERC20(_tokenAddressesToApprove[_i]).allowance(
1718
_batchSendContractAddress, _umbraContractAddress

contracts-periphery/script/DeployBatchSend.s.sol

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ contract DeployBatchSend is Script {
3030
/// @notice Deploy the contract to the list of networks,
3131
function run() public {
3232
// Compute the address the contract will be deployed to
33-
address expectedContractAddress = computeCreateAddress(msg.sender, EXPECTED_NONCE);
33+
address expectedContractAddress = vm.computeCreateAddress(msg.sender, EXPECTED_NONCE);
3434
console2.log("Expected contract address: %s", expectedContractAddress);
3535

3636
// Turn off fallback to default RPC URLs since they can be flaky.

contracts-periphery/test/ApproveBatchSendTokens.t.sol

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ contract ApproveBatchSendTokensTest is Test {
1717
address constant WBTC_ADDRESS = 0x2260FAC5E5542a773Aa44fBCfeDf7C193bc2C599;
1818
address[] tokensToApprove =
1919
[DAI_ADDRESS, LUSD_ADDRESS, RAI_ADDRESS, USDC_ADDRESS, USDT_ADDRESS, WBTC_ADDRESS];
20+
address owner = 0xB7EE870E2c49B2DEEe70003519cF056247Aac3D4;
2021

2122
function setUp() public {
2223
vm.createSelectFork(vm.rpcUrl("mainnet"), 18_428_858);
@@ -27,7 +28,10 @@ contract ApproveBatchSendTokensTest is Test {
2728
address[] memory tokenAddressesToApprove = new address[](1);
2829
tokenAddressesToApprove[0] = DAI_ADDRESS;
2930
approveTokensScript.run(
30-
umbraContractAddressOnMainnet, batchSendContractAddressOnMainnet, tokenAddressesToApprove
31+
owner,
32+
umbraContractAddressOnMainnet,
33+
batchSendContractAddressOnMainnet,
34+
tokenAddressesToApprove
3135
);
3236

3337
assertEq(
@@ -40,7 +44,7 @@ contract ApproveBatchSendTokensTest is Test {
4044

4145
function test_ApproveMultipleTokens() public {
4246
approveTokensScript.run(
43-
umbraContractAddressOnMainnet, batchSendContractAddressOnMainnet, tokensToApprove
47+
owner, umbraContractAddressOnMainnet, batchSendContractAddressOnMainnet, tokensToApprove
4448
);
4549

4650
for (uint256 _i; _i < tokensToApprove.length; _i++) {

contracts-periphery/test/DeployBatchSend.t.sol

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ contract DeployBatchSendTest is DeployBatchSend, Test {
1414
bytes batchSendCode;
1515

1616
function setUp() public {
17-
expectedContractAddress = computeCreateAddress(sender, EXPECTED_NONCE);
17+
expectedContractAddress = vm.computeCreateAddress(sender, EXPECTED_NONCE);
1818
umbraBatchSendTest = new UmbraBatchSend(IUmbra(UMBRA));
1919
batchSendCode = address(umbraBatchSendTest).code;
2020
}

contracts-periphery/test/UmbraBatchSend.t.sol

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,18 @@ abstract contract UmbraBatchSendTest is DeployUmbraTest {
2020
error NotSorted();
2121
error TooMuchEthSent();
2222

23+
function _sortSendDataByToken(UmbraBatchSend.SendData[] storage arr) internal {
24+
for (uint256 i = 0; i < arr.length - 1; i++) {
25+
for (uint256 j = 0; j < arr.length - i - 1; j++) {
26+
if (arr[j].tokenAddr > arr[j + 1].tokenAddr) {
27+
UmbraBatchSend.SendData memory temp = arr[j];
28+
arr[j] = arr[j + 1];
29+
arr[j + 1] = temp;
30+
}
31+
}
32+
}
33+
}
34+
2335
function setUp() public virtual override {
2436
super.setUp();
2537
router = new UmbraBatchSend(IUmbra(address(umbra)));
@@ -94,6 +106,8 @@ abstract contract UmbraBatchSendTest is DeployUmbraTest {
94106
sendData.push(UmbraBatchSend.SendData(alice, address(token), amount, pkx, ciphertext));
95107
sendData.push(UmbraBatchSend.SendData(bob, address(token), amount2, pkx, ciphertext));
96108

109+
_sortSendDataByToken(sendData);
110+
97111
uint256 totalToll = toll * sendData.length;
98112
token.approve(address(router), totalAmount);
99113
token2.approve(address(router), totalAmount2);

frontend/.env.example

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ OPTIMISTIC_ETHERSCAN_API_KEY=yourOptimisticEtherscanApiKey
33
POLYGONSCAN_API_KEY=yourPolygonscanApiKey
44
ARBISCAN_API_KEY=yourArbiscanApiKey
55

6-
INFURA_ID=yourKeyHere
76
BLOCKNATIVE_API_KEY=yourKeyHere
87
FORTMATIC_API_KEY=yourKeyHere
98
PORTIS_API_KEY=yourKeyHere

umbra-js/.env.example

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ OPTIMISTIC_ETHERSCAN_API_KEY=yourOptimisticEtherscanApiKey
33
POLYGONSCAN_API_KEY=yourPolygonscanApiKey
44
ARBISCAN_API_KEY=yourArbiscanApiKey
55
GNOSISSCAN_API_KEY=yourGnosisSafeScanApiKey
6-
INFURA_ID=zzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz
76
MAINNET_RPC_URL=yourMainnetRpcUrl
87
OPTIMISM_RPC_URL=yourOptimismRpcUrl
98
GNOSIS_CHAIN_RPC_URL=yourGnosisChainRpcUrl

umbra-js/hardhat.config.ts

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,11 +19,10 @@ const chainIds = {
1919
// Ensure that we have all the environment variables we need.
2020
const mnemonic = 'test test test test test test test test test test test junk';
2121

22-
const infuraApiKey = process.env.INFURA_ID;
23-
if (!infuraApiKey) throw new Error('Please set your INFURA_ID in a .env file');
24-
2522
function createTestnetConfig(network: keyof typeof chainIds): NetworkUserConfig {
26-
const url = `https://${network}.infura.io/v3/${infuraApiKey as string}`;
23+
const rpcUrlString = `${network.toUpperCase()}_RPC_URL`;
24+
const url = process.env[rpcUrlString];
25+
if (!url) throw new Error(`Please set the ${url} in a .env file`);
2726
return {
2827
accounts: {
2928
count: 10,
@@ -36,12 +35,14 @@ function createTestnetConfig(network: keyof typeof chainIds): NetworkUserConfig
3635
};
3736
}
3837

38+
const rpcUrlString = process.env.SEPOLIA_RPC_URL;
39+
if (!rpcUrlString) throw new Error('Please set the SEPOLIA_RPC_URL in a .env file');
3940
const config: HardhatUserConfig = {
4041
defaultNetwork: 'hardhat',
4142
networks: {
4243
hardhat: {
4344
forking: {
44-
url: `https://sepolia.infura.io/v3/${infuraApiKey}`,
45+
url: rpcUrlString,
4546
},
4647
chainId: chainIds.hardhat,
4748
accounts: {

umbra-js/test/cns.test.ts

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,11 @@ const resolution = new Resolution({
1111
uns: {
1212
locations: {
1313
Layer1: {
14-
url: `https://mainnet.infura.io/v3/${String(process.env.INFURA_ID)}`,
14+
url: `${String(process.env.MAINNET_RPC_URL)}`,
1515
network: 'mainnet',
1616
},
1717
Layer2: {
18-
url: `https://polygon-mainnet.infura.io/v3/${String(process.env.INFURA_ID)}`,
18+
url: `${String(process.env.POLYGON_RPC_URL)}`,
1919
network: 'polygon-mainnet',
2020
},
2121
},
@@ -43,9 +43,7 @@ describe('СNS functions', () => {
4343

4444
it('gets the public keys associated with a CNS address', async () => {
4545
const address = await resolution.addr(name, 'ETH');
46-
const ethersProvider = new StaticJsonRpcProvider(
47-
`https://polygon-mainnet.infura.io/v3/${String(process.env.INFURA_ID)}`
48-
);
46+
const ethersProvider = new StaticJsonRpcProvider(`${String(process.env.POLYGON_RPC_URL)}`);
4947
const keys = await utils.lookupRecipient(address, ethersProvider);
5048
expect(keys.spendingPublicKey).to.equal(nameSpendingPublicKey);
5149
expect(keys.viewingPublicKey).to.equal(nameViewingPublicKey);

umbra-js/test/utils.test.ts

Lines changed: 25 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,20 @@ import { Event } from '../src/ethers';
88

99
const ethersProvider = ethers.provider;
1010

11-
const INFURA_ID = <string>process.env.INFURA_ID;
12-
if (!INFURA_ID) throw new Error('Please set your INFURA_ID in a .env file');
11+
const MAINNET_RPC_URL = <string>process.env.MAINNET_RPC_URL;
12+
if (!MAINNET_RPC_URL) throw new Error('Please set your MAINNET_RPC_URL in a .env file');
13+
14+
const SEPOLIA_RPC_URL = <string>process.env.SEPOLIA_RPC_URL;
15+
if (!SEPOLIA_RPC_URL) throw new Error('Please set your SEPOLIA_RPC_URL in a .env file');
16+
17+
const POLYGON_RPC_URL = <string>process.env.POLYGON_RPC_URL;
18+
if (!POLYGON_RPC_URL) throw new Error('Please set your POLYGON_RPC_URL in a .env file');
19+
20+
const OPTIMISM_RPC_URL = <string>process.env.OPTIMISM_RPC_URL;
21+
if (!OPTIMISM_RPC_URL) throw new Error('Please set your OPTIMISM_RPC_URL in a .env file');
22+
23+
const ARBITRUM_ONE_RPC_URL = <string>process.env.ARBITRUM_ONE_RPC_URL;
24+
if (!ARBITRUM_ONE_RPC_URL) throw new Error('Please set your ARBITRUM_ONE_RPC_URL in a .env file');
1325

1426
// Public key and address corresponding to stratus4.eth
1527
const publicKey = '0x04458465db23fe07d148c8c9078d8b67497998a66f4f2aa479973a9cbaaf8b5a96e6ba166a389b8f794b68010849b64b91343e72c7fa4cfcc178607c4b1d4870ed'; // prettier-ignore
@@ -109,29 +121,29 @@ describe('Utilities', () => {
109121

110122
// --- Address, advanced mode on (i.e. don't use the StealthKeyRegistry) ---
111123
it('looks up recipients by address, advanced mode on', async () => {
112-
const ethersProvider = new StaticJsonRpcProvider(`https://sepolia.infura.io/v3/${String(process.env.INFURA_ID)}`);
124+
const ethersProvider = new StaticJsonRpcProvider(SEPOLIA_RPC_URL);
113125
const keys = await utils.lookupRecipient(address, ethersProvider, { advanced: true });
114126
expect(keys.spendingPublicKey).to.equal(pubKeysWallet.spendingPublicKey);
115127
expect(keys.viewingPublicKey).to.equal(pubKeysWallet.viewingPublicKey);
116128
});
117129

118130
it('looks up recipients by ENS, advanced mode on', async () => {
119-
const ethersProvider = new StaticJsonRpcProvider(`https://sepolia.infura.io/v3/${String(process.env.INFURA_ID)}`);
131+
const ethersProvider = new StaticJsonRpcProvider(SEPOLIA_RPC_URL);
120132
const keys = await utils.lookupRecipient('stratus4.eth', ethersProvider, { advanced: true });
121133
expect(keys.spendingPublicKey).to.equal(pubKeysWallet.spendingPublicKey);
122134
expect(keys.viewingPublicKey).to.equal(pubKeysWallet.viewingPublicKey);
123135
});
124136

125137
it.skip('looks up recipients by CNS, advanced mode on', async () => {
126-
const ethersProvider = new StaticJsonRpcProvider(`https://sepolia.infura.io/v3/${INFURA_ID}`);
138+
const ethersProvider = new StaticJsonRpcProvider(SEPOLIA_RPC_URL);
127139
const keys = await utils.lookupRecipient('udtestdev-msolomon.crypto', ethersProvider, { advanced: true });
128140
expect(keys.spendingPublicKey).to.equal(pubKeysWallet.spendingPublicKey);
129141
expect(keys.viewingPublicKey).to.equal(pubKeysWallet.viewingPublicKey);
130142
});
131143

132144
// --- Address, advanced mode off (i.e. use the StealthKeyRegistry) ---
133145
it('looks up recipients by address, advanced mode off', async () => {
134-
const ethersProvider = new StaticJsonRpcProvider(`https://sepolia.infura.io/v3/${INFURA_ID}`); // otherwise throws with unsupported network since we're on localhost
146+
const ethersProvider = new StaticJsonRpcProvider(SEPOLIA_RPC_URL); // otherwise throws with unsupported network since we're on localhost
135147
const keys = await utils.lookupRecipient(address, ethersProvider);
136148
expect(keys.spendingPublicKey).to.equal(pubKeysUmbra.spendingPublicKey);
137149
expect(keys.viewingPublicKey).to.equal(pubKeysUmbra.viewingPublicKey);
@@ -143,7 +155,7 @@ describe('Utilities', () => {
143155
});
144156

145157
it('looks up recipients by ENS, advanced mode off', async () => {
146-
const ethersProvider = new StaticJsonRpcProvider(`https://sepolia.infura.io/v3/${INFURA_ID}`);
158+
const ethersProvider = new StaticJsonRpcProvider(SEPOLIA_RPC_URL);
147159
const keys = await utils.lookupRecipient('stratus4.eth', ethersProvider);
148160
// These values are set on the Sepolia resolver
149161
expect(keys.spendingPublicKey).to.equal(pubKeysUmbra.spendingPublicKey);
@@ -181,37 +193,31 @@ describe('Utilities', () => {
181193

182194
// --- Address history by network ---
183195
it('looks up transaction history on mainnet', async () => {
184-
const ethersProvider = new StaticJsonRpcProvider(`https://mainnet.infura.io/v3/${INFURA_ID}`);
196+
const ethersProvider = new StaticJsonRpcProvider(MAINNET_RPC_URL);
185197
const txHash = await utils.getSentTransaction(address, ethersProvider);
186198
expect(txHash).to.have.lengthOf(66);
187199
});
188200

189201
it('looks up transaction history on sepolia', async () => {
190-
const ethersProvider = new StaticJsonRpcProvider(`https://sepolia.infura.io/v3/${INFURA_ID}`);
202+
const ethersProvider = new StaticJsonRpcProvider(SEPOLIA_RPC_URL);
191203
const txHash = await utils.getSentTransaction(address, ethersProvider);
192204
expect(txHash).to.have.lengthOf(66);
193205
});
194206

195207
it('looks up transaction history on polygon', async () => {
196-
const ethersProvider = new ethers.providers.StaticJsonRpcProvider(
197-
`https://polygon-mainnet.infura.io/v3/${INFURA_ID}`
198-
) as EthersProvider;
208+
const ethersProvider = new ethers.providers.StaticJsonRpcProvider(POLYGON_RPC_URL) as EthersProvider;
199209
const txHash = await utils.getSentTransaction(address, ethersProvider);
200210
expect(txHash).to.have.lengthOf(66);
201211
});
202212

203213
it('looks up transaction history on optimism', async () => {
204-
const ethersProvider = new ethers.providers.StaticJsonRpcProvider(
205-
`https://optimism-mainnet.infura.io/v3/${INFURA_ID}`
206-
) as EthersProvider;
214+
const ethersProvider = new ethers.providers.StaticJsonRpcProvider(OPTIMISM_RPC_URL) as EthersProvider;
207215
const txHash = await utils.getSentTransaction(address, ethersProvider);
208216
expect(txHash).to.have.lengthOf(66);
209217
});
210218

211219
it('looks up transaction history on arbitrum one', async () => {
212-
const ethersProvider = new ethers.providers.StaticJsonRpcProvider(
213-
`https://arbitrum-mainnet.infura.io/v3/${INFURA_ID}`
214-
) as EthersProvider;
220+
const ethersProvider = new ethers.providers.StaticJsonRpcProvider(ARBITRUM_ONE_RPC_URL) as EthersProvider;
215221
const txHash = await utils.getSentTransaction(address, ethersProvider);
216222
expect(txHash).to.have.lengthOf(66);
217223
});
@@ -238,7 +244,7 @@ describe('Utilities', () => {
238244

239245
it('throws when looking up an address that has not sent a transaction', async () => {
240246
const address = '0x0000000000000000000000000000000000000002';
241-
const ethersProvider = new StaticJsonRpcProvider(`https://sepolia.infura.io/v3/${INFURA_ID}`); // otherwise throws with unsupported network since we're on localhost
247+
const ethersProvider = new StaticJsonRpcProvider(SEPOLIA_RPC_URL); // otherwise throws with unsupported network since we're on localhost
242248
const errorMsg = `Address ${address} has not registered stealth keys. Please ask them to setup their Umbra account`;
243249
await expectRejection(utils.lookupRecipient(address, ethersProvider), errorMsg);
244250
});

0 commit comments

Comments
 (0)