Skip to content

Commit

Permalink
Fix docs and contracts config section
Browse files Browse the repository at this point in the history
  • Loading branch information
Siegrift committed Oct 27, 2023
1 parent 7c23c2c commit 8671916
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 17 deletions.
7 changes: 3 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -115,13 +115,12 @@ A record of chain configurations. The record key is the chain ID. For example:

##### `contracts`

A record of contract addresses used by Airseeker. If not specified, the addresses are loaded from
[Airnode protocol v1](https://github.com/api3dao/airnode-protocol-v1).
A record of contract addresses used by Airseeker.

###### Api3ServerV1 _(optional)_

The address of the Api3ServerV1 contract. If not specified, the address is loaded from the Airnode protocol v1
repository.
The address of the Api3ServerV1 contract. If not specified, the address is loaded from the
[Airnode protocol v1](https://github.com/api3dao/airnode-protocol-v1) repository.

###### DapiDataRegistry

Expand Down
24 changes: 13 additions & 11 deletions src/config/schema.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,30 +15,28 @@ const gasSettings = {
maxScalingMultiplier: 2,
};

test('validates example config', async () => {
test('validates example config', () => {
const exampleConfig = JSON.parse(readFileSync(join(__dirname, '../../config/airseeker.example.json'), 'utf8'));

// The mnemonic is not interpolated (and thus invalid).
await expect(configSchema.parseAsync(exampleConfig)).rejects.toStrictEqual(
expect(() => configSchema.parse(exampleConfig)).toThrow(
new ZodError([
{
code: 'custom',
message: 'Invalid mnemonic',
path: ['sponsorWalletMnemonic'],
},
{
validation: 'url',
code: 'invalid_string',
message: 'Invalid url',
path: ['chains', '31337', 'providers', 'hardhat', 'url'],
},
{
code: 'custom',
message: 'Invalid mnemonic',
path: ['sponsorWalletMnemonic'],
},
])
);

const exampleSecrets = dotenv.parse(readFileSync(join(__dirname, '../../config/secrets.example.env'), 'utf8'));
await expect(configSchema.parseAsync(interpolateSecrets(exampleConfig, exampleSecrets))).resolves.toStrictEqual(
expect.any(Object)
);
expect(configSchema.parse(interpolateSecrets(exampleConfig, exampleSecrets))).toStrictEqual(expect.any(Object));
});

describe('chains schema', () => {
Expand Down Expand Up @@ -73,7 +71,7 @@ describe('chains schema', () => {
});
});

it('uses loads the contract address from airnode-protocol-v1', () => {
it('uses the contract address from airnode-protocol-v1', () => {
const chains = {
'1': {
providers: {
Expand Down Expand Up @@ -111,6 +109,9 @@ describe('chains schema', () => {
url: 'http://localhost:8545',
},
},
contracts: {
DapiDataRegistry: '0xDD78254f864F97f65e2d86541BdaEf88A504D2B2',
},
__Temporary__DapiDataRegistry: {
airnodeToSignedApiUrl: {},
dataFeedIdToBeacons: {},
Expand Down Expand Up @@ -187,6 +188,7 @@ describe('chains schema', () => {
'31337': {
contracts: {
Api3ServerV1: '0xe7f1725E7734CE288F8367e1Bb143E90bb3F0512',
DapiDataRegistry: '0xDD78254f864F97f65e2d86541BdaEf88A504D2B2',
},
providers: {},
__Temporary__DapiDataRegistry: {
Expand Down
5 changes: 3 additions & 2 deletions src/config/schema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ export const optionalChainSchema = z
.object({
providers: z.record(providerSchema), // The record key is the provider "nickname"
__Temporary__DapiDataRegistry: temporaryDapiDataRegistrySchema,
contracts: optionalContractsSchema.optional(),
contracts: optionalContractsSchema,
gasSettings: gasSettingsSchema,
dataFeedUpdateInterval: z.number().positive(),
dataFeedBatchSize: z.number().positive(),
Expand Down Expand Up @@ -109,7 +109,8 @@ export const chainsSchema = z
Object.entries(chains).map(([chainId, chain]) => {
const { contracts } = chain;
const parsedContracts = contractsSchema.safeParse({
Api3ServerV1: contracts?.Api3ServerV1 ?? references.Api3ServerV1[chainId],
Api3ServerV1: contracts.Api3ServerV1 ?? references.Api3ServerV1[chainId],
DapiDataRegistry: contracts.DapiDataRegistry,
});
if (!parsedContracts.success) {
ctx.addIssue({
Expand Down

0 comments on commit 8671916

Please sign in to comment.