diff --git a/package.json b/package.json index af09b20e..b5992d05 100644 --- a/package.json +++ b/package.json @@ -21,9 +21,9 @@ "loadtest:byron-staging": "artillery run test/loadtest/byron-staging-config.yml", "publish-packages": "yarn workspaces run publish", "service-dependencies": "docker-compose config --services | grep -v \"cardano-graphql\" | xargs docker-compose", - "start:mainnet": "GENESIS_FILE_SHELLEY=${PWD}/config/network/mainnet/genesis_shelley.json HASURA_URI=http://localhost:8090 yarn workspace @cardano-graphql/server start", + "start:mainnet": "GENESIS_FILE_BYRON=${PWD}/config/network/mainnet/genesis_byron.json GENESIS_FILE_SHELLEY=${PWD}/config/network/mainnet/genesis_shelley.json HASURA_URI=http://localhost:8090 yarn workspace @cardano-graphql/server start", "start:shelley_testnet": "GENESIS_FILE_SHELLEY=${PWD}/config/network/shelley_testnet/genesis_shelley.json yarn workspace @cardano-graphql/server start", - "start:mainnet_candidate_3": "GENESIS_FILE_SHELLEY=${PWD}/config/network/mainnet_candidate_3/genesis_shelley.json yarn workspace @cardano-graphql/server start", + "start:mainnet_candidate_3": "GENESIS_FILE_BYRON=${PWD}/config/network/mainnet_candidate_3/genesis_byron.json GENESIS_FILE_SHELLEY=${PWD}/config/network/mainnet_candidate_3/genesis_shelley.json yarn workspace @cardano-graphql/server start", "test": "yarn workspaces run test" }, "contributors": [ diff --git a/packages/api-genesis/schema.graphql b/packages/api-genesis/schema.graphql index 40bcee5c..2f7fa123 100644 --- a/packages/api-genesis/schema.graphql +++ b/packages/api-genesis/schema.graphql @@ -3,15 +3,60 @@ schema { } scalar JSONObject +scalar Timestamp type Query { genesis: Genesis! } type Genesis { + byron: ByronGenesis shelley: ShelleyGenesis } +type ByronBlockVersionData { + scriptVersion: Int! + slotDuration: Int! + maxBlockSize: Int! + maxHeaderSize: Int! + maxTxSize: Int! + maxProposalSize: Int! + mpcThd: String! + heavyDelThd: String! + updateVoteThd: String! + updateProposalThd: String! + updateImplicit: String! + softforkRule: ByronSoftForkRule! + txFeePolicy: ByronTxFeePolicy! + unlockStakeEpoch: String! +} + +type ByronGenesis { + bootStakeholders: JSONObject! + heavyDelegation: JSONObject! + startTime: Timestamp! + nonAvvmBalances: JSONObject! + blockVersionData: ByronBlockVersionData! + protocolConsts: ByronProtocolConsts! + avvmDistr: JSONObject! +} + +type ByronProtocolConsts { + k: Int! + protocolMagic: Int +} + +type ByronSoftForkRule { + initThd: String! + minThd: String! + thdDecrement: String! +} + +type ByronTxFeePolicy { + summand: String! + multiplier: String! +} + type ShelleyGenesis { activeSlotsCoeff: Float! epochLength: Int! @@ -22,7 +67,7 @@ type ShelleyGenesis { networkId: String! networkMagic: Int! protocolMagicId: Int! - protocolParams: ProtocolParams! + protocolParams: ShelleyProtocolParams! securityParam: Int! slotLength: Int! slotsPerKESPeriod: Int! @@ -31,7 +76,7 @@ type ShelleyGenesis { updateQuorum: Int! } -type ProtocolParams { +type ShelleyProtocolParams { a0: Float! decentralisationParam: Int! eMax: Int! diff --git a/packages/api-genesis/src/example_queries/allInfo.graphql b/packages/api-genesis/src/example_queries/allInfoShelley.graphql similarity index 100% rename from packages/api-genesis/src/example_queries/allInfo.graphql rename to packages/api-genesis/src/example_queries/allInfoShelley.graphql diff --git a/packages/api-genesis/src/example_queries/keyNetworkInfoByronShelley.graphql b/packages/api-genesis/src/example_queries/keyNetworkInfoByronShelley.graphql new file mode 100644 index 00000000..48457b2d --- /dev/null +++ b/packages/api-genesis/src/example_queries/keyNetworkInfoByronShelley.graphql @@ -0,0 +1,29 @@ +query keyNetworkInfo { + genesis { + byron { + blockVersionData { + scriptVersion + slotDuration + maxBlockSize + maxHeaderSize + maxProposalSize + maxTxSize + } + startTime + protocolConsts { + k + protocolMagic + } + } + shelley { + epochLength + maxLovelaceSupply + networkId + networkMagic + securityParam + slotLength + slotsPerKESPeriod + systemStart + } + } +} \ No newline at end of file diff --git a/packages/api-genesis/src/example_queries/keyNetworkInfo.graphql b/packages/api-genesis/src/example_queries/keyNetworkInfoShelley.graphql similarity index 100% rename from packages/api-genesis/src/example_queries/keyNetworkInfo.graphql rename to packages/api-genesis/src/example_queries/keyNetworkInfoShelley.graphql diff --git a/packages/api-genesis/src/executableSchema.ts b/packages/api-genesis/src/executableSchema.ts index 3347b401..d74228bb 100644 --- a/packages/api-genesis/src/executableSchema.ts +++ b/packages/api-genesis/src/executableSchema.ts @@ -1,11 +1,12 @@ import fs from 'fs' import path from 'path' import { makeExecutableSchema } from '@graphql-tools/schema' -import { JSONObjectResolver } from 'graphql-scalars' +import { JSONObjectResolver, TimestampResolver } from 'graphql-scalars' import { Resolvers, Genesis } from './graphql_types' export const scalarResolvers = { - JSONObject: JSONObjectResolver + JSONObject: JSONObjectResolver, + Timestamp: TimestampResolver } as any export function buildSchema (genesis: Genesis) { diff --git a/packages/api-genesis/test/__snapshots__/genesis.query.test.ts.snap b/packages/api-genesis/test/__snapshots__/genesis.query.test.ts.snap index 1e1d7603..416b4121 100644 --- a/packages/api-genesis/test/__snapshots__/genesis.query.test.ts.snap +++ b/packages/api-genesis/test/__snapshots__/genesis.query.test.ts.snap @@ -1,6 +1,6 @@ // Jest Snapshot v1, https://goo.gl/fbAQLP -exports[`genesis Shelley testnet Returns all information from genesis.json 1`] = ` +exports[`genesis Single-era Returns all information from genesis.json 1`] = ` Object { "genesis": Object { "shelley": Object { @@ -67,102 +67,50 @@ Object { } `; -exports[`genesis Shelley testnet Returns all information from genesis.json 2`] = ` +exports[`genesis Single-era Returns key information about the network 1`] = ` Object { "genesis": Object { "shelley": Object { - "activeSlotsCoeff": 0.05, "epochLength": 21600, - "genDelegs": Object { - "46accc160a32598fd87b14d823fd25ec6ca3388316c404ce5aa06dca": Object { - "delegate": "e47b777efea3146b1aa18fde95ddbd3de38f068f529997ff4141e484", - "vrf": "56c2364bb4a90d0f674ae1b758d5c19b2f1622b3f763799f1f0793cfc4591daf", - }, - "c800db9af0cfe4997163e730ff2eeadc984f4ed29bdfeed37fb87c05": Object { - "delegate": "252a3464a2e6d3e824e3dc63629276838227f92f2c6b6cc45fc16138", - "vrf": "ca23e0093e70086bf92788f0efcbe45c1727f19d4376a94118d5bfaebdcca257", - }, - "cbdf7c87a498440cc16fb16b6d3a957de7979252de695e38344aee52": Object { - "delegate": "609114bdfa04f8fa2dc3450306427a6bb803a1cce84a2c3c760a7e4b", - "vrf": "48a39ab96ed61faa76b69a08f39282e6a4fb458020e024ee6b612c93f4439c99", - }, - }, - "initialFunds": Object { - "6034d2c8b6373a4a3326259c1fbccfc45405bd20552097d960868b40a9": 10000000000000000, - "6051d08fc78ca26cfc41b839f6c30b25ccf45f81594d4147a6f392a058": 1000000000000000, - }, - "maxKESEvolutions": 120, "maxLovelaceSupply": "45000000000000000", "networkId": "Testnet", "networkMagic": 42, - "protocolMagicId": 42, - "protocolParams": Object { - "a0": 0.3, - "decentralisationParam": 1, - "eMax": 18, - "extraEntropy": Object { - "tag": "NeutralNonce", - }, - "keyDeposit": 400000, - "maxBlockBodySize": 65536, - "maxBlockHeaderSize": 1100, - "maxTxSize": 16384, - "minFeeA": 44, - "minFeeB": 155381, - "minPoolCost": 0, - "minUTxOValue": 0, - "nOpt": 250, - "poolDeposit": 500000000, - "protocolVersion": Object { - "major": 0, - "minor": 0, - }, - "rho": 0.0022, - "tau": 0.05, - }, "securityParam": 108, "slotLength": 1, "slotsPerKESPeriod": 3600, - "staking": Object { - "pools": Object {}, - "stake": Object {}, - }, "systemStart": "2020-07-13T11:00:00Z", - "updateQuorum": 3, }, }, } `; -exports[`genesis Shelley testnet Returns key information about the network 1`] = ` +exports[`genesis Spanning-eras Returns key information about the network 1`] = ` Object { "genesis": Object { - "shelley": Object { - "epochLength": 21600, - "maxLovelaceSupply": "45000000000000000", - "networkId": "Testnet", - "networkMagic": 42, - "securityParam": 108, - "slotLength": 1, - "slotsPerKESPeriod": 3600, - "systemStart": "2020-07-13T11:00:00Z", + "byron": Object { + "blockVersionData": Object { + "maxBlockSize": 2000000, + "maxHeaderSize": 2000000, + "maxProposalSize": 700, + "maxTxSize": 4096, + "scriptVersion": 0, + "slotDuration": 20000, + }, + "protocolConsts": Object { + "k": 2160, + "protocolMagic": 764824073, + }, + "startTime": 1506203091, }, - }, -} -`; - -exports[`genesis Shelley testnet Returns key information about the network 2`] = ` -Object { - "genesis": Object { "shelley": Object { - "epochLength": 21600, + "epochLength": 432000, "maxLovelaceSupply": "45000000000000000", - "networkId": "Testnet", - "networkMagic": 42, - "securityParam": 108, + "networkId": "Mainnet", + "networkMagic": 764824073, + "securityParam": 2160, "slotLength": 1, - "slotsPerKESPeriod": 3600, - "systemStart": "2020-07-13T11:00:00Z", + "slotsPerKESPeriod": 129600, + "systemStart": "2017-09-23T21:44:51Z", }, }, } diff --git a/packages/api-genesis/test/genesis.query.test.ts b/packages/api-genesis/test/genesis.query.test.ts index 7e56ebcb..07017883 100644 --- a/packages/api-genesis/test/genesis.query.test.ts +++ b/packages/api-genesis/test/genesis.query.test.ts @@ -4,37 +4,50 @@ import util from '@cardano-graphql/util' import { TestClient } from '@cardano-graphql/util-dev' import { buildClient } from './util' -const shelleyTestnetGenesis = require('../../../config/network/shelley_testnet/genesis_shelley.json') -const mainnetCandidateGenesis = require('../../../config/network/mainnet_candidate/genesis_shelley.json') +const genesisFiles = { + mainnet: { + byron: require('../../../config/network/mainnet/genesis_byron.json'), + shelley: require('../../../config/network/mainnet/genesis_shelley.json') + }, + shelley_testnet: { + shelley: require('../../../config/network/shelley_testnet/genesis_shelley.json') + } +} function loadQueryNode (name: string): Promise { return util.loadQueryNode(path.resolve(__dirname, '..', 'src', 'example_queries'), name) } describe('genesis', () => { - let shelleyTestnetClient: TestClient - let mainnetCandidateClient: TestClient + let client: TestClient - describe('Shelley testnet', () => { + describe('Single-era', () => { beforeAll(async () => { - shelleyTestnetClient = await buildClient(shelleyTestnetGenesis) - mainnetCandidateClient = await buildClient(mainnetCandidateGenesis) + client = await buildClient(genesisFiles.shelley_testnet) }) it('Returns key information about the network', async () => { - const query = { query: await loadQueryNode('keyNetworkInfo') } - const shelleyTestnetResult = await shelleyTestnetClient.query(query) - expect(shelleyTestnetResult.data).toMatchSnapshot() - const mainnetCandidateResult = await mainnetCandidateClient.query(query) - expect(mainnetCandidateResult.data).toMatchSnapshot() + const query = { query: await loadQueryNode('keyNetworkInfoShelley') } + const result = await client.query(query) + expect(result.data).toMatchSnapshot() }) it('Returns all information from genesis.json', async () => { - const query = { query: await loadQueryNode('allInfo') } - const shelleyTestnetResult = await shelleyTestnetClient.query(query) - expect(shelleyTestnetResult.data).toMatchSnapshot() - const mainnetCandidateResult = await mainnetCandidateClient.query(query) - expect(mainnetCandidateResult.data).toMatchSnapshot() + const query = { query: await loadQueryNode('allInfoShelley') } + const result = await client.query(query) + expect(result.data).toMatchSnapshot() + }) + }) + + describe('Spanning-eras', () => { + beforeAll(async () => { + client = await buildClient(genesisFiles.mainnet) + }) + + it('Returns key information about the network', async () => { + const query = { query: await loadQueryNode('keyNetworkInfoByronShelley') } + const result = await client.query(query) + expect(result.data).toMatchSnapshot() }) }) }) diff --git a/packages/server/src/index.ts b/packages/server/src/index.ts index c123a728..f63fe7b2 100644 --- a/packages/server/src/index.ts +++ b/packages/server/src/index.ts @@ -21,9 +21,13 @@ async function boot () { const plugins: PluginDefinition[] = [] const app = express() - if (config.genesisFileShelley !== undefined) { - schemas.push(buildGenesisSchema({ shelley: require(config.genesisFileShelley) })) + if (config.genesisFileByron !== undefined || config.genesisFileShelley !== undefined) { + schemas.push(buildGenesisSchema({ + ...config.genesisFileByron !== undefined ? { byron: require(config.genesisFileByron) } : {}, + ...config.genesisFileShelley !== undefined ? { shelley: require(config.genesisFileShelley) } : {} + })) } + if (config.hasuraUri !== undefined) { const db = new Db(config.hasuraUri) await db.init()