Fix relayer funder - fix identifier parsing & error logging (#843)

* Fix relayer funder by fixing identifier parsing (w/ tests), and ensuring errors are logged

* nit

* more test keys
pull/859/head
Trevor Porter 2 years ago committed by GitHub
parent f24aa96a0c
commit d24eaa4e32
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 5
      typescript/infra/scripts/funding/fund-relayers-from-deployer.ts
  2. 26
      typescript/infra/src/agents/agent.ts
  3. 58
      typescript/infra/test/agents.test.ts

@ -1,6 +1,7 @@
import { Console } from 'console'; import { Console } from 'console';
import { ethers } from 'ethers'; import { ethers } from 'ethers';
import { Gauge, Registry } from 'prom-client'; import { Gauge, Registry } from 'prom-client';
import { format } from 'util';
import { ChainConnection, CompleteChainMap } from '@abacus-network/sdk'; import { ChainConnection, CompleteChainMap } from '@abacus-network/sdk';
@ -247,7 +248,9 @@ function relayerKeyInfo(relayerKey: AgentKey) {
main().catch((err) => { main().catch((err) => {
error('Error occurred in main', { error('Error occurred in main', {
error: err, // JSON.stringifying an Error returns '{}'.
// This is a workaround from https://stackoverflow.com/a/60370781
error: format(err),
}); });
process.exit(1); process.exit(1);
}); });

@ -69,43 +69,43 @@ export class ReadOnlyAgentKey extends AgentKey {
address: string, address: string,
): ReadOnlyAgentKey { ): ReadOnlyAgentKey {
const regex = const regex =
/.*([a-zA-Z0-9]+)-([a-zA-Z0-9]+)-key-([a-zA-Z0-9]+)-?([a-zA-Z0-9]+)?-?([0-9]+)?/g; /(alias\/)?([a-zA-Z0-9]+)-([a-zA-Z0-9]+)-key-([a-zA-Z0-9]+)-?([a-zA-Z0-9]+)?-?([0-9]+)?/g;
const matches = regex.exec(identifier); const matches = regex.exec(identifier);
if (!matches) { if (!matches) {
throw Error('Invalid identifier'); throw Error('Invalid identifier');
} }
const context = assertContext(matches[1]); const context = assertContext(matches[2]);
const environment = matches[2]; const environment = matches[3];
// If matches[4] is undefined, this key doesn't have a chainName, and matches[3] // If matches[5] is undefined, this key doesn't have a chainName, and matches[4]
// is the role name. // is the role name.
if (matches[4] === undefined) { if (matches[5] === undefined) {
return new ReadOnlyAgentKey( return new ReadOnlyAgentKey(
environment, environment,
context, context,
assertRole(matches[3]), assertRole(matches[4]),
identifier, identifier,
address, address,
); );
} else if (matches[5] === undefined) { } else if (matches[6] === undefined) {
// If matches[5] is undefined, this key doesn't have an index. // If matches[6] is undefined, this key doesn't have an index.
return new ReadOnlyAgentKey( return new ReadOnlyAgentKey(
environment, environment,
context, context,
assertRole(matches[4]), assertRole(matches[5]),
identifier, identifier,
address, address,
assertChain(matches[3]), assertChain(matches[4]),
); );
} else { } else {
return new ReadOnlyAgentKey( return new ReadOnlyAgentKey(
environment, environment,
context, context,
assertRole(matches[4]), assertRole(matches[5]),
identifier, identifier,
address, address,
assertChain(matches[3]), assertChain(matches[4]),
parseInt(matches[5]), parseInt(matches[6]),
); );
} }
} }

@ -0,0 +1,58 @@
import { expect } from 'chai';
import { Contexts } from '../config/contexts';
import { ReadOnlyAgentKey } from '../src/agents/agent';
import { AgentAwsKey } from '../src/agents/aws';
import { AgentGCPKey } from '../src/agents/gcp';
import { KEY_ROLE_ENUM } from '../src/agents/roles';
describe('ReadOnlyAgentKey', () => {
describe('fromSerializedAddress', () => {
it('correctly parses identifiers', () => {
const addressZero = '0x0000000000000000000000000000000000000000';
const environment = 'test';
const context = Contexts.Abacus;
const chainName = 'test1';
// Enough to satisfy the constructor of AgentAwsKey
const mockAgentConfig: any = {
aws: {
region: 'us-east-1',
},
environment,
context,
};
// AWS and GCP agent keys to get the identifiers from
// and ensure they can be correctly parsed
const testKeys = [
new AgentGCPKey(environment, context, KEY_ROLE_ENUM.Deployer),
new AgentGCPKey(environment, context, KEY_ROLE_ENUM.Relayer, chainName),
new AgentGCPKey(
environment,
context,
KEY_ROLE_ENUM.Validator,
chainName,
0,
),
new AgentAwsKey(mockAgentConfig, KEY_ROLE_ENUM.Deployer),
new AgentAwsKey(mockAgentConfig, KEY_ROLE_ENUM.Relayer, chainName),
new AgentAwsKey(mockAgentConfig, KEY_ROLE_ENUM.Validator, chainName, 0),
];
for (const testKey of testKeys) {
const identifier = testKey.identifier;
const readOnly = ReadOnlyAgentKey.fromSerializedAddress(
identifier,
addressZero,
);
expect(readOnly.environment).to.eq(testKey.environment);
expect(readOnly.context).to.eq(testKey.context);
expect(readOnly.role).to.eq(testKey.role);
expect(readOnly.chainName).to.eq(testKey.chainName);
expect(readOnly.index).to.eq(testKey.index);
}
});
});
});
Loading…
Cancel
Save