Skip to content

Commit

Permalink
Added test cases for PocketProvider.
Browse files Browse the repository at this point in the history
  • Loading branch information
ricmoo committed Oct 9, 2020
1 parent a62d20d commit 5a6d9a3
Showing 1 changed file with 78 additions and 3 deletions.
81 changes: 78 additions & 3 deletions packages/tests/src.ts/test-providers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -438,6 +438,7 @@ const ApiKeys: Record<string, string> = {
alchemy: "YrPw6SWb20vJDRFkhWq8aKnTQ8JRNRHM",
etherscan: "FPFGK6JSW2UHJJ2666FG93KP7WC999MNW7",
infura: "49a0efa3aaee4fd99797bfa94d8ce2f1",
pocket: "5f7f8547b90218002e9ce9dd",
};

const providerFunctions: Array<ProviderDescription> = [
Expand All @@ -464,7 +465,7 @@ const providerFunctions: Array<ProviderDescription> = [
/*
{
name: "CloudflareProvider",
networks: [ "homestead" ],
networks: [ "default", "homestead" ],
create: (network: string) => {
return new ethers.providers.CloudflareProvider(network);
}
Expand Down Expand Up @@ -497,6 +498,16 @@ const providerFunctions: Array<ProviderDescription> = [
throw new Error("not tested");
}
},
{
name: "PocketProvider",
networks: [ "default", "homestead" ],
create: (network: string) => {
if (network == "default") {
return new ethers.providers.PocketProvider(null, ApiKeys.pocket);
}
return new ethers.providers.PocketProvider(network, ApiKeys.pocket);
}
},
{
name: "Web3Provider",
networks: [ ],
Expand Down Expand Up @@ -720,8 +731,6 @@ describe("Test Provider Methods", function() {
after(async function() {
this.timeout(300000);

console.log("*** Sweeping funds back to faucet");

// Wait until the funding is complete
await fundReceipt;

Expand Down Expand Up @@ -936,6 +945,72 @@ describe("Test API Key Formatting", function() {
});

});

it("Pocket API key", function() {
const applicationId = "someApplicationId";
const applicationSecretKey = "someApplicationSecret";

// Test simple applicationId
const apiKeyString = ethers.providers.PocketProvider.getApiKey(applicationId);
assert.equal(apiKeyString.applicationId, applicationId);
assert.ok(apiKeyString.applicationSecretKey == null);

// Test complex API key with applicationId
const apiKeyObject = ethers.providers.PocketProvider.getApiKey({
applicationId
});
assert.equal(apiKeyObject.applicationId, applicationId);
assert.ok(apiKeyObject.applicationSecretKey == null);

// Test complex API key with applicationId and applicationSecretKey
const apiKeyObject2 = ethers.providers.PocketProvider.getApiKey({
applicationId: applicationId,
applicationSecretKey: applicationSecretKey
});
assert.equal(apiKeyObject2.applicationId, applicationId);
assert.equal(apiKeyObject2.applicationSecretKey, applicationSecretKey);

// Fails on invalid applicationId type
assert.throws(() => {
const apiKey = ethers.providers.PocketProvider.getApiKey({
applicationId: 1234,
applicationSecretKey: applicationSecretKey
});
console.log(apiKey);
}, (error: any) => {
return (error.argument === "applicationId" && error.reason === "applicationSecretKey requires an applicationId");
});

// Fails on invalid projectSecret type
assert.throws(() => {
const apiKey = ethers.providers.PocketProvider.getApiKey({
applicationId: applicationId,
applicationSecretKey: 1234
});
console.log(apiKey);
}, (error: any) => {
return (error.argument === "applicationSecretKey" && error.reason === "invalid applicationSecretKey");
});

{
const provider = new ethers.providers.PocketProvider("homestead", {
applicationId: applicationId,
applicationSecretKey: applicationSecretKey
});
assert.equal(provider.network.name, "homestead");
assert.equal(provider.applicationId, applicationId);
assert.equal(provider.applicationSecretKey, applicationSecretKey);
}

// Attempt an unsupported network
assert.throws(() => {
const provider = new ethers.providers.PocketProvider("imaginary");
console.log(provider);
}, (error: any) => {
return (error.argument === "network" && error.reason === "unsupported network");
});
});

});

describe("Test WebSocketProvider", function() {
Expand Down

0 comments on commit 5a6d9a3

Please sign in to comment.