Skip to content

Commit

Permalink
Fix e2e test using erc721 authorizer
Browse files Browse the repository at this point in the history
  • Loading branch information
Siegrift committed Mar 14, 2023
1 parent 950f5ec commit b3db6aa
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -184,6 +184,7 @@ async function fetchErc721AuthorizationStatuses(

return [[groupLog], null];
}
// TODO: It would be nice to log whether the requester is authorized or not

This comment has been minimized.

Copy link
@dcroote

dcroote Mar 15, 2023

Contributor

I had the same thought and added DEBUG level logging elsewhere (so that the log is generated independent of authorizer). The e2e now outputs:

DEBUG Requester:0x9A676e781A523b5d0C0e43731313A708CB607508 is authorized to access Endpoint ID:0x13dea3311fe0d6b84f4daeab831befbc49e19e6494c41e9e065a09c3c68f43b6 for Request ID:0x75a4bebef242385238ac98aa1e79505cddd0a163924961f394897dd84b1c11e1 Coordinator-ID:32a934c46ff00e16, Chain-ID:31337, Provider:EVM local

const decodedMulticall = decodeMulticall(requesterAuthorizerWithErc721, goData.data);
const authorizationsById = applyErc721Authorizations(apiCalls, erc721s, decodedMulticall);
Expand Down
21 changes: 19 additions & 2 deletions packages/airnode-node/test/e2e/erc721-authorizers.feature.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import { erc721Mocks } from '@api3/airnode-protocol';
import { ethers } from 'ethers';
import * as local from '../../src/workers/local-handlers';
import { operation } from '../fixtures';
import { increaseTestTimeout, deployAirnodeAndMakeRequests, fetchAllLogNames } from '../setup/e2e';
Expand All @@ -6,14 +8,29 @@ increaseTestTimeout();

it('deploys a requesterAuthorizerWithErc721 contract and authorizes requests', async () => {
const requests = [operation.buildFullRequest()];
const { provider, deployment } = await deployAirnodeAndMakeRequests(__filename, requests);
const { provider, deployment, deployerIndex, mnemonic } = await deployAirnodeAndMakeRequests(__filename, requests);

// Send the NFT to the requester
const deployer = provider.getSigner(deployerIndex);

This comment has been minimized.

Copy link
@Siegrift

Siegrift Mar 14, 2023

Author Contributor

The operation repo deploys the MockErc721 which mints 10 NFTs for the address that deployed the contract.

const onERC721ReceivedArguments = ethers.utils.defaultAbiCoder.encode(

This comment has been minimized.

Copy link
@Siegrift

Siegrift Mar 14, 2023

Author Contributor

See: https://github.com/api3dao/nft-authorizer/blob/f4bba58837f6d9d3b28254f3c2764cbe6e3bb88f/test/RequesterAuthorizerWithErc721.sol.js#L1418 for the logic of the lines below.

The naming is not nice, and it would be nice to refactor the airnode-protocol mocks and operations repo a bit.

['address', 'uint256', 'address'],
[ethers.Wallet.fromMnemonic(mnemonic).address, 31337, deployment.requesters.MockRrpRequesterFactory]
);
await erc721Mocks.MockErc721Factory.connect(deployment.erc721s.MockErc721Factory, deployer)[
'safeTransferFrom(address,address,uint256,bytes)'
](
await deployer.getAddress(),
deployment.authorizers.MockRequesterAuthorizerWithErc721Factory,
0,
onERC721ReceivedArguments
);

// Configure authorizers so that only the requesterAuthorizersWithErc721 can authorize
// An empty requesterEndpointAuthorizers array means that no authorizers are required hence the 0x0...
const erc721Address = deployment.erc721s.MockErc721Factory;
const requesterAuthorizersWithErc721Address = deployment.authorizers.MockRequesterAuthorizerWithErc721Factory;
const config = local.loadConfig();
config.chains[0].authorizers.requesterEndpointAuthorizers = [];
config.chains[0].authorizers.requesterEndpointAuthorizers = ['0x0000000000000000000000000000000000000000'];

This comment has been minimized.

Copy link
@dcroote

dcroote Mar 15, 2023

Contributor

This is no longer needed: I changed the behavior so that if all authorizers are empty, all requests are authorized (as expected), but if any authorizers are non-empty, then those authorize.

config.chains[0].authorizers.crossChainRequesterAuthorizers = [];
config.chains[0].authorizers.crossChainRequesterAuthorizersWithErc721 = [];
config.chains[0].authorizers.requesterAuthorizersWithErc721 = [
Expand Down
2 changes: 1 addition & 1 deletion packages/airnode-node/test/setup/e2e/testing.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,5 +35,5 @@ export const deployAirnodeAndMakeRequests = async (filename: string, requests?:
mockReadFileSync('config.json', JSON.stringify(config));
jest.spyOn(validator, 'unsafeParseConfigWithSecrets').mockReturnValue(config);

return { deployment, provider: buildProvider(), config, mnemonic };
return { deployment, provider: buildProvider(), config, mnemonic, deployerIndex };
};

0 comments on commit b3db6aa

Please sign in to comment.