-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #2 from decentraland/feat/add-blockchain-types
feat: add network and chain types
- Loading branch information
Showing
8 changed files
with
136 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
import { generateValidator, JSONSchema, ValidateFunction } from '../validation' | ||
|
||
/** | ||
* Different supported chain ids | ||
* @alpha | ||
*/ | ||
export enum ChainId { | ||
ETHEREUM_MAINNET = 1, | ||
ETHEREUM_ROPSTEN = 3, | ||
ETHEREUM_RINKEBY = 4, | ||
ETHEREUM_GOERLI = 5, | ||
ETHEREUM_KOVAN = 42, | ||
MATIC_MAINNET = 89, | ||
MATIC_MUMBAI = 13881, | ||
} | ||
|
||
/** | ||
* @alpha | ||
*/ | ||
export namespace ChainId { | ||
export const schema: JSONSchema<ChainId> = { | ||
type: 'number', | ||
enum: Object.values(ChainId), | ||
} | ||
|
||
export const validate: ValidateFunction<ChainId> = generateValidator(schema) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
import { generateValidator, JSONSchema, ValidateFunction } from '../validation' | ||
|
||
/** | ||
* Different supported networks | ||
* @alpha | ||
*/ | ||
export enum Network { | ||
ETHEREUM = 'ETHEREUM', | ||
MATIC = 'MATIC', | ||
} | ||
|
||
/** | ||
* @alpha | ||
*/ | ||
export namespace Network { | ||
export const schema: JSONSchema<Network> = { | ||
type: 'string', | ||
enum: Object.values(Network), | ||
} | ||
|
||
export const validate: ValidateFunction<Network> = generateValidator(schema) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,7 @@ | ||
// export the utils | ||
export * from "./validation" | ||
export * from './validation' | ||
|
||
// export all the types | ||
export { MetaTransaction } from "./dapps/meta-transactions" | ||
export { ChainId } from './dapps/chain-id' | ||
export { Network } from './dapps/network' | ||
export { MetaTransaction } from './dapps/meta-transactions' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
import expect from 'expect' | ||
import { ChainId } from '../src' | ||
import { testTypeSignature } from './test-utils' | ||
|
||
describe('ChainId tests', () => { | ||
const chainId: ChainId = ChainId.ETHEREUM_KOVAN | ||
|
||
testTypeSignature(ChainId, chainId) | ||
|
||
it('static tests must pass', () => { | ||
expect(ChainId.validate(chainId)).toEqual(true) | ||
expect(ChainId.validate(null)).toEqual(false) | ||
expect(ChainId.validate({})).toEqual(false) | ||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
import expect from 'expect' | ||
import { Network } from '../src' | ||
import { testTypeSignature } from './test-utils' | ||
|
||
describe('Network tests', () => { | ||
const network: Network = Network.ETHEREUM | ||
|
||
testTypeSignature(Network, network) | ||
|
||
it('static tests must pass', () => { | ||
expect(Network.validate(network)).toEqual(true) | ||
expect(Network.validate(null)).toEqual(false) | ||
expect(Network.validate({})).toEqual(false) | ||
}) | ||
}) |