Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Get metadata for contracts verified on celoscan #169

Closed
wants to merge 47 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
47 commits
Select commit Hold shift + click to select a range
7bca628
Get metadata for contracts verified on celoscan
aaronmgdr Feb 29, 2024
9052b84
WIP -- DOES NOT WORK
aaronmgdr Mar 1, 2024
446e722
Get metadata for contracts verified on celoscan
aaronmgdr Feb 29, 2024
4aa4473
WIP -- DOES NOT WORK
aaronmgdr Mar 1, 2024
91d96ef
used celoscans verified point
aaronmgdr Mar 19, 2024
dbf852e
add fetching of implementation contract from celoscan
aaronmgdr Mar 19, 2024
71fa248
and we have a pass
aaronmgdr Mar 21, 2024
e41ebfa
remove debug logs
aaronmgdr Mar 21, 2024
08b367d
updating fetchMetaData to also fetch from celoscan is the best approach.
aaronmgdr Mar 26, 2024
74c7685
add test for contract name seting
aaronmgdr Mar 26, 2024
3070be6
add docs and changesets
aaronmgdr Mar 26, 2024
152ada8
fix changeset type
aaronmgdr Mar 26, 2024
1da5d82
expand timeouts for tests to prevent cannot log after tests errors
aaronmgdr Mar 26, 2024
206fc19
logically the new tests would be the source of issue
aaronmgdr Mar 26, 2024
70f88fc
we dont need to parse everytime this.getKit is called.
aaronmgdr Mar 26, 2024
be2ed70
try mocking the calls to network
aaronmgdr Mar 27, 2024
feafd27
redo docs and unmock
aaronmgdr Mar 27, 2024
f48f0a8
expect proposal is created
aaronmgdr Mar 27, 2024
9c65553
skip new tests
aaronmgdr Mar 27, 2024
f5c9169
get the mocks working
aaronmgdr Mar 27, 2024
28adddd
fix expect() call, change snapshot
shazarre Mar 27, 2024
142f1d9
ensure calls to fetch are mocked
aaronmgdr Mar 28, 2024
622c0f5
oh no mellony
aaronmgdr Mar 28, 2024
e90a7f8
import cross fetch always as default so all imports are the same and …
aaronmgdr Mar 28, 2024
019fc4b
logging the error is noisy for the users
aaronmgdr Mar 28, 2024
ee9da6c
remove the sleep. maybe this is actually doing the opposite of what i…
aaronmgdr Mar 28, 2024
97bd916
celo cli tests just passed
aaronmgdr Mar 28, 2024
8396faf
output as csv over json because its tighter. json output takes over t…
aaronmgdr Mar 28, 2024
fa262eb
why would these be timing out now?
aaronmgdr Mar 28, 2024
d289bc2
force exit like contractkit tests do
aaronmgdr Mar 29, 2024
d5a5832
probably best to leave setting the timezone
aaronmgdr Mar 29, 2024
5bf4d4c
cleanup
aaronmgdr Mar 29, 2024
4edf7a3
wrong file
aaronmgdr Mar 29, 2024
5d6deef
add expectation of transactions and remove handle detection
aaronmgdr Mar 29, 2024
883dc66
less special cases. more configuration
aaronmgdr Apr 3, 2024
378733c
Merge branch 'master' into aarmgdr/celoscan
aaronmgdr Apr 3, 2024
1ebb72b
Merge branch 'master' into aarmgdr/celoscan
aaronmgdr Apr 4, 2024
06f79ec
Merge branch 'master' into aarmgdr/celoscan
aaronmgdr May 14, 2024
8c44694
Merge branch 'master' into aarmgdr/celoscan
aaronmgdr May 15, 2024
7243537
do this on advise from leszek
aaronmgdr Jun 12, 2024
7d05240
oops wrong file
aaronmgdr Jun 12, 2024
f8de85a
Merge branch 'master' into aarmgdr/celoscan
aaronmgdr Jun 25, 2024
fd58038
docs
aaronmgdr Jun 25, 2024
bc675a8
no need to use snapshot here
aaronmgdr Jun 25, 2024
b6a921c
example is the proper test domain
aaronmgdr Jun 25, 2024
31ff6fb
show warning
aaronmgdr Jun 25, 2024
7964290
Merge branch 'master' into aarmgdr/celoscan
aaronmgdr Jun 28, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/tough-ears-study.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@celo/celocli': minor
---

Add ability to build and view governance proposals which interact with contracts verified on celoscan
aaronmgdr marked this conversation as resolved.
Show resolved Hide resolved
5 changes: 5 additions & 0 deletions .changeset/young-foxes-compete.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@celo/explorer': minor
---

Adds Celoscan as source for fetching verified contract metadata
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -91,3 +91,4 @@ package.json-e
# Ignore generated credentials from google-github-actions/auth
gha-creds-*.json
transactions.json
transactions2.json
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,7 @@ ___
▸ **getContractMappingFromSourcify**(`address`): `Promise`\<`undefined` \| [`ContractMapping`](../interfaces/base.ContractMapping.md)\>

Returns the ContractMapping for the contract at that address, or undefined
by looking up the contract address in Sourcify.
by looking up the contract address on various contract verification services.

#### Parameters

Expand Down
29 changes: 20 additions & 9 deletions docs/sdk/explorer/classes/sourcify.Metadata.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ light runtime verification.
- [abi](sourcify.Metadata.md#abi)
- [contractName](sourcify.Metadata.md#contractname)
- [fnMapping](sourcify.Metadata.md#fnmapping)
- [implementationAddress](sourcify.Metadata.md#implementationaddress)

### Accessors

Expand All @@ -42,15 +43,15 @@ light runtime verification.
| :------ | :------ |
| `connection` | `Connection` |
| `address` | `string` |
| `response` | `any` |
| `response` | [`MetadataResponse`](../interfaces/sourcify.MetadataResponse.md) |

#### Returns

[`Metadata`](sourcify.Metadata.md)

#### Defined in

[sourcify.ts:73](https://github.com/celo-org/developer-tooling/blob/master/packages/sdk/explorer/src/sourcify.ts#L73)
[sourcify.ts:76](https://github.com/celo-org/developer-tooling/blob/master/packages/sdk/explorer/src/sourcify.ts#L76)

## Properties

Expand All @@ -60,7 +61,7 @@ light runtime verification.

#### Defined in

[sourcify.ts:65](https://github.com/celo-org/developer-tooling/blob/master/packages/sdk/explorer/src/sourcify.ts#L65)
[sourcify.ts:67](https://github.com/celo-org/developer-tooling/blob/master/packages/sdk/explorer/src/sourcify.ts#L67)

___

Expand All @@ -70,7 +71,7 @@ ___

#### Defined in

[sourcify.ts:66](https://github.com/celo-org/developer-tooling/blob/master/packages/sdk/explorer/src/sourcify.ts#L66)
[sourcify.ts:68](https://github.com/celo-org/developer-tooling/blob/master/packages/sdk/explorer/src/sourcify.ts#L68)

___

Expand All @@ -80,7 +81,17 @@ ___

#### Defined in

[sourcify.ts:67](https://github.com/celo-org/developer-tooling/blob/master/packages/sdk/explorer/src/sourcify.ts#L67)
[sourcify.ts:70](https://github.com/celo-org/developer-tooling/blob/master/packages/sdk/explorer/src/sourcify.ts#L70)

___

### implementationAddress

• **implementationAddress**: ``null`` \| `string` = `null`

#### Defined in

[sourcify.ts:69](https://github.com/celo-org/developer-tooling/blob/master/packages/sdk/explorer/src/sourcify.ts#L69)

## Accessors

Expand All @@ -100,7 +111,7 @@ ___

#### Defined in

[sourcify.ts:83](https://github.com/celo-org/developer-tooling/blob/master/packages/sdk/explorer/src/sourcify.ts#L83)
[sourcify.ts:88](https://github.com/celo-org/developer-tooling/blob/master/packages/sdk/explorer/src/sourcify.ts#L88)

## Methods

Expand All @@ -127,7 +138,7 @@ and array of AbiItems matching the query

#### Defined in

[sourcify.ts:152](https://github.com/celo-org/developer-tooling/blob/master/packages/sdk/explorer/src/sourcify.ts#L152)
[sourcify.ts:158](https://github.com/celo-org/developer-tooling/blob/master/packages/sdk/explorer/src/sourcify.ts#L158)

___

Expand All @@ -151,7 +162,7 @@ an AbiItem if found or null

#### Defined in

[sourcify.ts:136](https://github.com/celo-org/developer-tooling/blob/master/packages/sdk/explorer/src/sourcify.ts#L136)
[sourcify.ts:142](https://github.com/celo-org/developer-tooling/blob/master/packages/sdk/explorer/src/sourcify.ts#L142)

___

Expand All @@ -167,4 +178,4 @@ Turn the ABI into a mapping of function selectors to ABI items.

#### Defined in

[sourcify.ts:119](https://github.com/celo-org/developer-tooling/blob/master/packages/sdk/explorer/src/sourcify.ts#L119)
[sourcify.ts:125](https://github.com/celo-org/developer-tooling/blob/master/packages/sdk/explorer/src/sourcify.ts#L125)
2 changes: 2 additions & 0 deletions docs/sdk/explorer/interfaces/sourcify.MetadataResponse.md
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,8 @@ ___
| Name | Type |
| :------ | :------ |
| `compilationTarget?` | `Record`\<`string`, `string`\> |
| `implementation?` | `string` |
| `name?` | `string` |

#### Defined in

Expand Down
8 changes: 4 additions & 4 deletions docs/sdk/explorer/modules/sourcify.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@

▸ **fetchMetadata**(`connection`, `contract`, `strict?`): `Promise`\<[`Metadata`](../classes/sourcify.Metadata.md) \| ``null``\>

Fetch the sourcify response and instantiate a Metadata wrapper class around it.
Try a full_match but fallback to partial_match when not strict.
Fetch the sourcify or celoscan response and instantiate a Metadata wrapper class around it.
Try a full_match but fallback to partial_match when not strict. (only valid for sourcify)

#### Parameters

Expand All @@ -42,7 +42,7 @@ Metadata or null

#### Defined in

[sourcify.ts:179](https://github.com/celo-org/developer-tooling/blob/master/packages/sdk/explorer/src/sourcify.ts#L179)
[sourcify.ts:185](https://github.com/celo-org/developer-tooling/blob/master/packages/sdk/explorer/src/sourcify.ts#L185)

___

Expand Down Expand Up @@ -73,4 +73,4 @@ the implementation address or null

#### Defined in

[sourcify.ts:228](https://github.com/celo-org/developer-tooling/blob/master/packages/sdk/explorer/src/sourcify.ts#L228)
[sourcify.ts:300](https://github.com/celo-org/developer-tooling/blob/master/packages/sdk/explorer/src/sourcify.ts#L300)
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@

#### Defined in

[proposals.ts:466](https://github.com/celo-org/developer-tooling/blob/master/packages/sdk/governance/src/proposals.ts#L466)
[proposals.ts:464](https://github.com/celo-org/developer-tooling/blob/master/packages/sdk/governance/src/proposals.ts#L464)

## Methods

Expand All @@ -47,7 +47,7 @@

#### Defined in

[proposals.ts:468](https://github.com/celo-org/developer-tooling/blob/master/packages/sdk/governance/src/proposals.ts#L468)
[proposals.ts:466](https://github.com/celo-org/developer-tooling/blob/master/packages/sdk/governance/src/proposals.ts#L466)

___

Expand All @@ -61,4 +61,4 @@ ___

#### Defined in

[proposals.ts:473](https://github.com/celo-org/developer-tooling/blob/master/packages/sdk/governance/src/proposals.ts#L473)
[proposals.ts:471](https://github.com/celo-org/developer-tooling/blob/master/packages/sdk/governance/src/proposals.ts#L471)
2 changes: 1 addition & 1 deletion docs/sdk/governance/classes/proposals.ProposalBuilder.md
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ ___

#### Defined in

[proposals.ts:460](https://github.com/celo-org/developer-tooling/blob/master/packages/sdk/governance/src/proposals.ts#L460)
[proposals.ts:458](https://github.com/celo-org/developer-tooling/blob/master/packages/sdk/governance/src/proposals.ts#L458)

___

Expand Down
2 changes: 2 additions & 0 deletions packages/cli/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,5 @@ oclif.manifest.json
src/generated
.devchain/
.devchain.tar.gz
transactions.json
transactions2.json
3 changes: 3 additions & 0 deletions packages/cli/jest.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,7 @@ module.exports = {
setupFilesAfterEnv: ['@celo/dev-utils/lib/matchers', '<rootDir>/src/test-utils/setupAfterEnv.ts'],
globalSetup: '<rootDir>/src/test-utils/setup.global.ts',
globalTeardown: '<rootDir>/src/test-utils/teardown.global.ts',
testTimeout: 10 * 1000, // set default timeout to 10 seconds
slowTestThreshold: 10, // this is also 10 seconds.
openHandlesTimeout: 0, // disables
}
1 change: 1 addition & 0 deletions packages/cli/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@
"@types/ledgerhq__hw-transport-node-hid": "^4.22.5",
"@types/node": "^18.7.16",
"@types/prompts": "^1.1.1",
"fetch-mock": "^9.11.0",
"jest": "^29.7.0",
"oclif": "^4.3.4",
"prettier": "1.19.1",
Expand Down
18 changes: 13 additions & 5 deletions packages/cli/src/base.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,16 @@ import { LocalWallet } from '@celo/wallet-local'
import _TransportNodeHid from '@ledgerhq/hw-transport-node-hid'
import { Command, Flags } from '@oclif/core'
import chalk from 'chalk'
import debugFactory from 'debug'
import net from 'net'
import Web3 from 'web3'
import { CustomFlags } from './utils/command'
import { getNodeUrl } from './utils/config'
import { getFeeCurrencyContractWrapper } from './utils/fee-currency'
import { requireNodeIsSynced } from './utils/helpers'

const debug = debugFactory('cli:base')

export abstract class BaseCommand extends Command {
static flags = {
privateKey: Flags.string({
Expand Down Expand Up @@ -126,10 +129,14 @@ export abstract class BaseCommand extends Command {
}

async getKit() {
if (!this._kit) {
this._kit = newKitFromWeb3(await this.getWeb3())
// return now if kit already has been built instead of doing all that parsing and awaiting
// because this.getKit is called when closing down the command by not returning early this.parse would be called and weird logs occure
if (this._kit) {
return this._kit
}

this._kit = newKitFromWeb3(await this.getWeb3())

const res = await this.parse()
if (res.flags && res.flags.privateKey && !res.flags.useLedger && !res.flags.useAKV) {
this._kit.connection.addAccount(res.flags.privateKey)
Expand Down Expand Up @@ -231,10 +238,11 @@ export abstract class BaseCommand extends Command {
async finally(arg: Error | undefined): Promise<any> {
try {
if (arg) {
console.error('received error while cleaning up', arg)
aaronmgdr marked this conversation as resolved.
Show resolved Hide resolved
debug('received error while cleaning up:', arg)
}
const kit = await this.getKit()
kit.connection.stop()
// we only need to stop the kit if one exists. if there is an error on this.parse for flags then there is no kit and thus none to stop
// if we use this.getKit then this.parse is called and errors out. throwing and logging failed to close the connection
this._kit && this._kit.connection.stop()
} catch (error) {
this.log(`Failed to close the connection: ${error}`)
}
Expand Down
2 changes: 1 addition & 1 deletion packages/cli/src/commands/election/list.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,5 +52,5 @@ describe('election:list cmd', () => {
],
]
`)
})
}, 4000)
})
Loading
Loading