Skip to content

Commit

Permalink
Refactor network:info for L2 epochs (#348)
Browse files Browse the repository at this point in the history
  • Loading branch information
shazarre authored Sep 27, 2024
1 parent 431c8c5 commit 76d09b7
Show file tree
Hide file tree
Showing 12 changed files with 388 additions and 58 deletions.
5 changes: 5 additions & 0 deletions .changeset/dull-kangaroos-reply.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@celo/celocli': patch
---

Fix network:info command when in L2
5 changes: 5 additions & 0 deletions .changeset/twenty-fans-listen.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@celo/contractkit': minor
---

Adds support for firstKnownEpoch, getFirstBlockAtEpoch, getLastBlockAtEpoch on EpochManager wrapper
20 changes: 10 additions & 10 deletions docs/command-line-interface/network.md
Original file line number Diff line number Diff line change
Expand Up @@ -65,18 +65,18 @@ View general network information such as the current block number
```
USAGE
$ celocli network:info [--gasCurrency
0x1234567890123456789012345678901234567890] [--globalHelp] [-n <value>]
0x1234567890123456789012345678901234567890] [--globalHelp] [--lastN <value>]
FLAGS
-n, --lastN=<value>
[default: 1] Fetch info about the last n epochs
--gasCurrency=0x1234567890123456789012345678901234567890
Use a specific gas currency for transaction fees (defaults to CELO if no gas
currency is supplied). It must be a whitelisted token.
--globalHelp
View all available global flags
--gasCurrency=0x1234567890123456789012345678901234567890 Use a specific gas currency
for transaction fees
(defaults to CELO if no gas
currency is supplied). It
must be a whitelisted token.
--globalHelp View all available global
flags
--lastN=<value> [default: 1] Fetch info
about the last n epochs
DESCRIPTION
View general network information such as the current block number
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,12 @@ Contract handling epoch management.
- [eventTypes](wrappers_EpochManager.EpochManagerWrapper.md#eventtypes)
- [events](wrappers_EpochManager.EpochManagerWrapper.md#events)
- [finishNextEpochProcess](wrappers_EpochManager.EpochManagerWrapper.md#finishnextepochprocess)
- [firstKnownEpoch](wrappers_EpochManager.EpochManagerWrapper.md#firstknownepoch)
- [getCurrentEpochNumber](wrappers_EpochManager.EpochManagerWrapper.md#getcurrentepochnumber)
- [getElected](wrappers_EpochManager.EpochManagerWrapper.md#getelected)
- [getEpochProcessingStatus](wrappers_EpochManager.EpochManagerWrapper.md#getepochprocessingstatus)
- [getFirstBlockAtEpoch](wrappers_EpochManager.EpochManagerWrapper.md#getfirstblockatepoch)
- [getLastBlockAtEpoch](wrappers_EpochManager.EpochManagerWrapper.md#getlastblockatepoch)
- [isOnEpochProcess](wrappers_EpochManager.EpochManagerWrapper.md#isonepochprocess)
- [isTimeForNextEpoch](wrappers_EpochManager.EpochManagerWrapper.md#istimefornextepoch)
- [methodIds](wrappers_EpochManager.EpochManagerWrapper.md#methodids)
Expand Down Expand Up @@ -157,7 +160,31 @@ ___

#### Defined in

[packages/sdk/contractkit/src/wrappers/EpochManager.ts:54](https://github.com/celo-org/developer-tooling/blob/master/packages/sdk/contractkit/src/wrappers/EpochManager.ts#L54)
[packages/sdk/contractkit/src/wrappers/EpochManager.ts:61](https://github.com/celo-org/developer-tooling/blob/master/packages/sdk/contractkit/src/wrappers/EpochManager.ts#L61)

___

### firstKnownEpoch

**firstKnownEpoch**: (...`args`: []) => `Promise`\<`number`\>

#### Type declaration

▸ (`...args`): `Promise`\<`number`\>

##### Parameters

| Name | Type |
| :------ | :------ |
| `...args` | [] |

##### Returns

`Promise`\<`number`\>

#### Defined in

[packages/sdk/contractkit/src/wrappers/EpochManager.ts:31](https://github.com/celo-org/developer-tooling/blob/master/packages/sdk/contractkit/src/wrappers/EpochManager.ts#L31)

___

Expand All @@ -181,7 +208,7 @@ ___

#### Defined in

[packages/sdk/contractkit/src/wrappers/EpochManager.ts:31](https://github.com/celo-org/developer-tooling/blob/master/packages/sdk/contractkit/src/wrappers/EpochManager.ts#L31)
[packages/sdk/contractkit/src/wrappers/EpochManager.ts:32](https://github.com/celo-org/developer-tooling/blob/master/packages/sdk/contractkit/src/wrappers/EpochManager.ts#L32)

___

Expand All @@ -205,7 +232,7 @@ ___

#### Defined in

[packages/sdk/contractkit/src/wrappers/EpochManager.ts:38](https://github.com/celo-org/developer-tooling/blob/master/packages/sdk/contractkit/src/wrappers/EpochManager.ts#L38)
[packages/sdk/contractkit/src/wrappers/EpochManager.ts:45](https://github.com/celo-org/developer-tooling/blob/master/packages/sdk/contractkit/src/wrappers/EpochManager.ts#L45)

___

Expand All @@ -229,7 +256,55 @@ ___

#### Defined in

[packages/sdk/contractkit/src/wrappers/EpochManager.ts:39](https://github.com/celo-org/developer-tooling/blob/master/packages/sdk/contractkit/src/wrappers/EpochManager.ts#L39)
[packages/sdk/contractkit/src/wrappers/EpochManager.ts:46](https://github.com/celo-org/developer-tooling/blob/master/packages/sdk/contractkit/src/wrappers/EpochManager.ts#L46)

___

### getFirstBlockAtEpoch

**getFirstBlockAtEpoch**: (...`args`: [epoch: string \| number]) => `Promise`\<`number`\>

#### Type declaration

▸ (`...args`): `Promise`\<`number`\>

##### Parameters

| Name | Type |
| :------ | :------ |
| `...args` | [epoch: string \| number] |

##### Returns

`Promise`\<`number`\>

#### Defined in

[packages/sdk/contractkit/src/wrappers/EpochManager.ts:37](https://github.com/celo-org/developer-tooling/blob/master/packages/sdk/contractkit/src/wrappers/EpochManager.ts#L37)

___

### getLastBlockAtEpoch

**getLastBlockAtEpoch**: (...`args`: [epoch: string \| number]) => `Promise`\<`number`\>

#### Type declaration

▸ (`...args`): `Promise`\<`number`\>

##### Parameters

| Name | Type |
| :------ | :------ |
| `...args` | [epoch: string \| number] |

##### Returns

`Promise`\<`number`\>

#### Defined in

[packages/sdk/contractkit/src/wrappers/EpochManager.ts:42](https://github.com/celo-org/developer-tooling/blob/master/packages/sdk/contractkit/src/wrappers/EpochManager.ts#L42)

___

Expand All @@ -253,7 +328,7 @@ ___

#### Defined in

[packages/sdk/contractkit/src/wrappers/EpochManager.ts:36](https://github.com/celo-org/developer-tooling/blob/master/packages/sdk/contractkit/src/wrappers/EpochManager.ts#L36)
[packages/sdk/contractkit/src/wrappers/EpochManager.ts:43](https://github.com/celo-org/developer-tooling/blob/master/packages/sdk/contractkit/src/wrappers/EpochManager.ts#L43)

___

Expand All @@ -277,7 +352,7 @@ ___

#### Defined in

[packages/sdk/contractkit/src/wrappers/EpochManager.ts:37](https://github.com/celo-org/developer-tooling/blob/master/packages/sdk/contractkit/src/wrappers/EpochManager.ts#L37)
[packages/sdk/contractkit/src/wrappers/EpochManager.ts:44](https://github.com/celo-org/developer-tooling/blob/master/packages/sdk/contractkit/src/wrappers/EpochManager.ts#L44)

___

Expand Down Expand Up @@ -315,7 +390,7 @@ ___

#### Defined in

[packages/sdk/contractkit/src/wrappers/EpochManager.ts:53](https://github.com/celo-org/developer-tooling/blob/master/packages/sdk/contractkit/src/wrappers/EpochManager.ts#L53)
[packages/sdk/contractkit/src/wrappers/EpochManager.ts:60](https://github.com/celo-org/developer-tooling/blob/master/packages/sdk/contractkit/src/wrappers/EpochManager.ts#L60)

## Accessors

Expand Down Expand Up @@ -349,7 +424,7 @@ BaseWrapperForGoverning.address

#### Defined in

[packages/sdk/contractkit/src/wrappers/EpochManager.ts:56](https://github.com/celo-org/developer-tooling/blob/master/packages/sdk/contractkit/src/wrappers/EpochManager.ts#L56)
[packages/sdk/contractkit/src/wrappers/EpochManager.ts:63](https://github.com/celo-org/developer-tooling/blob/master/packages/sdk/contractkit/src/wrappers/EpochManager.ts#L63)

___

Expand All @@ -363,7 +438,7 @@ ___

#### Defined in

[packages/sdk/contractkit/src/wrappers/EpochManager.ts:118](https://github.com/celo-org/developer-tooling/blob/master/packages/sdk/contractkit/src/wrappers/EpochManager.ts#L118)
[packages/sdk/contractkit/src/wrappers/EpochManager.ts:125](https://github.com/celo-org/developer-tooling/blob/master/packages/sdk/contractkit/src/wrappers/EpochManager.ts#L125)

___

Expand All @@ -383,7 +458,7 @@ ___

#### Defined in

[packages/sdk/contractkit/src/wrappers/EpochManager.ts:69](https://github.com/celo-org/developer-tooling/blob/master/packages/sdk/contractkit/src/wrappers/EpochManager.ts#L69)
[packages/sdk/contractkit/src/wrappers/EpochManager.ts:76](https://github.com/celo-org/developer-tooling/blob/master/packages/sdk/contractkit/src/wrappers/EpochManager.ts#L76)

___

Expand Down
23 changes: 22 additions & 1 deletion docs/sdk/contractkit/modules/test_utils_utils.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

- [currentEpochNumber](test_utils_utils.md#currentepochnumber)
- [mineToNextEpoch](test_utils_utils.md#minetonextepoch)
- [startAndFinishEpochProcess](test_utils_utils.md#startandfinishepochprocess)
- [topUpWithToken](test_utils_utils.md#topupwithtoken)

## Functions
Expand Down Expand Up @@ -54,6 +55,26 @@ ___

___

### startAndFinishEpochProcess

**startAndFinishEpochProcess**(`kit`): `Promise`\<`void`\>

#### Parameters

| Name | Type |
| :------ | :------ |
| `kit` | [`ContractKit`](../classes/kit.ContractKit.md) |

#### Returns

`Promise`\<`void`\>

#### Defined in

[packages/sdk/contractkit/src/test-utils/utils.ts:43](https://github.com/celo-org/developer-tooling/blob/master/packages/sdk/contractkit/src/test-utils/utils.ts#L43)

___

### topUpWithToken

**topUpWithToken**(`kit`, `stableToken`, `recipientAddress`, `amount`): `Promise`\<`void`\>
Expand All @@ -73,4 +94,4 @@ ___

#### Defined in

[packages/sdk/contractkit/src/test-utils/utils.ts:43](https://github.com/celo-org/developer-tooling/blob/master/packages/sdk/contractkit/src/test-utils/utils.ts#L43)
[packages/sdk/contractkit/src/test-utils/utils.ts:58](https://github.com/celo-org/developer-tooling/blob/master/packages/sdk/contractkit/src/test-utils/utils.ts#L58)
2 changes: 1 addition & 1 deletion docs/sdk/contractkit/modules/wrappers_EpochManager.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,4 +29,4 @@

#### Defined in

[packages/sdk/contractkit/src/wrappers/EpochManager.ts:131](https://github.com/celo-org/developer-tooling/blob/master/packages/sdk/contractkit/src/wrappers/EpochManager.ts#L131)
[packages/sdk/contractkit/src/wrappers/EpochManager.ts:138](https://github.com/celo-org/developer-tooling/blob/master/packages/sdk/contractkit/src/wrappers/EpochManager.ts#L138)
81 changes: 79 additions & 2 deletions packages/cli/src/commands/network/info-l2.test.ts
Original file line number Diff line number Diff line change
@@ -1,16 +1,93 @@
import { newKitFromWeb3 } from '@celo/contractkit'
import { testWithAnvilL2 } from '@celo/dev-utils/lib/anvil-test'
import { timeTravel } from '@celo/dev-utils/lib/ganache-test'
import { stripAnsiCodesFromNestedArray, testLocallyWithWeb3Node } from '../../test-utils/cliUtils'
import EpochsSwitch from '../epochs/switch'
import Info from './info'
process.env.NO_SYNCCHECK = 'true'

testWithAnvilL2('network:info', (web3) => {
test('runs', async () => {
beforeAll(async () => {
const kit = newKitFromWeb3(web3)
const epochManager = await kit.contracts.getEpochManager()
const epochDuration = await epochManager.epochDuration()
const accounts = await web3.eth.getAccounts()

// Switch epochs 3 times
for (let i = 0; i < 3; i++) {
await timeTravel(epochDuration * 2, web3)
await testLocallyWithWeb3Node(EpochsSwitch, ['--from', accounts[0]], web3)
}
})

it('runs for latest epoch', async () => {
const spy = jest.spyOn(console, 'log')
await testLocallyWithWeb3Node(Info, [], web3)

expect(stripAnsiCodesFromNestedArray(spy.mock.calls)).toMatchInlineSnapshot(`
[
[
"blockNumber: 359
epochDuration: 86400
epochs:
number: 7
start: 359",
],
]
`)
})

it('runs for last 3 epochs', async () => {
const spy = jest.spyOn(console, 'log')
await testLocallyWithWeb3Node(Info, ['--lastN', '3'], web3)

expect(stripAnsiCodesFromNestedArray(spy.mock.calls)).toMatchInlineSnapshot(`
[
[
"blockNumber: 359
epochDuration: 86400
epochs:
0:
number: 7
start: 359
1:
end: 358
number: 6
start: 356
2:
end: 355
number: 5
start: 353",
],
]
`)
})

it('runs for last 100 epochs, but displays only epoch that exist', async () => {
const spy = jest.spyOn(console, 'log')
await testLocallyWithWeb3Node(Info, ['--lastN', '100'], web3)

expect(stripAnsiCodesFromNestedArray(spy.mock.calls)).toMatchInlineSnapshot(`
[
[
"blockNumber: 350",
"blockNumber: 359
epochDuration: 86400
epochs:
0:
number: 7
start: 359
1:
end: 358
number: 6
start: 356
2:
end: 355
number: 5
start: 353
3:
end: 352
number: 4
start: 300",
],
]
`)
Expand Down
Loading

0 comments on commit 76d09b7

Please sign in to comment.