Skip to content

Commit

Permalink
wip: test: checklist, pt.2
Browse files Browse the repository at this point in the history
  • Loading branch information
egasimus committed May 27, 2024
1 parent 70abcc0 commit 49a6e1b
Show file tree
Hide file tree
Showing 9 changed files with 107 additions and 64 deletions.
8 changes: 6 additions & 2 deletions packages/cw/cw-connection.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ export class CWChain extends Chain {
static async connect (
properties: { chainId?: ChainId }&({ url: string|URL }|{ urls: Iterable<string|URL> })
): Promise<CWChain> {
const { chainId, url, urls = [ url ] } = properties as any
const { chainId, url, urls = [ url ] } = (properties || {}) as any
const chain = new this({
chainId,
connections: [],
Expand Down Expand Up @@ -69,7 +69,11 @@ export class CWChain extends Chain {
): Promise<CWAgent> {
let identity: CWIdentity
if (!args[0]) {
identity = new CWMnemonicIdentity({})
identity = new CWMnemonicIdentity({
bech32Prefix: this.bech32Prefix,
coinType: this.coinType,
hdAccountIndex: this.hdAccountIndex
})
} else if (typeof (args[0] as any).mnemonic === 'string') {
identity = new CWMnemonicIdentity({
mnemonic: (args[0] as any).mnemonic
Expand Down
5 changes: 4 additions & 1 deletion packages/cw/cw.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,4 +39,7 @@ export * from './cw-chains'
export * as Staking from './cw-staking'

import { CWChain } from './cw-connection'
export const connect = CWChain.connect

export function connect (...args: Parameters<typeof CWChain.connect>) {
return CWChain.connect(...args)
}
4 changes: 2 additions & 2 deletions packages/namada/namada-connection.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,14 +44,14 @@ export class Namada extends CW.Chain {
decoder?: string|URL|Uint8Array
}
): Promise<Namada> {
if (properties.decoder) {
if (properties?.decoder) {
await initDecoder(properties.decoder)
} else {
new CW.Console('Namada').warn(
"You didn't provide the 'decoder' property; trying to decode Namada objects will fail."
)
}
return await super.connect(properties) as Namada
return await super.connect(properties || {}) as Namada
}

/** Connect to Namada using `testnetChainId` and `testnetURLs`. */
Expand Down
19 changes: 17 additions & 2 deletions packages/namada/namada.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,22 @@ export {
} from './namada-console'

import { Namada } from './namada-connection'
export const connect = Namada.connect
export const testnet = Namada.testnet

export function connect (...args: Parameters<typeof Namada.connect>) {
return Namada.connect(...args)
}

export function testnet (...args: Parameters<typeof Namada.testnet>) {
return Namada.testnet(...args)
}

export function mainnet (...args: never) {
throw new Error(
'Connection details for Namada mainnet are not built into Fadroma yet. ' +
'You can pass them to Namada.connect function if you have them.'
)
}

export const testnetChainId = Namada.testnetChainId

export const testnetURLs = Namada.testnetURLs
1 change: 1 addition & 0 deletions packages/oci/oci-connection.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ export { Mock, Error, Console }
export const console = new Console('@fadroma/oci')

export class OCI extends Chain {

static mock (callback?: Function) {
return new this({
chainId: 'mock',
Expand Down
6 changes: 6 additions & 0 deletions packages/oci/oci.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,9 @@ export {
OCIImage,
OCIContainer,
} from './oci-program'

import { OCI } from './oci-connection'
export async function connect (...args: ConstructorParameters<typeof OCI>) {
if (!args[0]) args[0] = {} as any
return new OCI(...args)
}
4 changes: 2 additions & 2 deletions packages/scrt/scrt-chain.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ export class ScrtChain extends Chain {
return this.connections[0]
}

static async connect ({ chainId, urls }: {
static async connect ({ chainId, urls = [] }: {
chainId: ChainId,
urls: (string|URL)[]
}): Promise<ScrtChain> {
Expand All @@ -30,7 +30,7 @@ export class ScrtChain extends Chain {
if (args.length === 0) {
return new ScrtAgent({
chain: this,
api: new SecretNetworkClient(),
api: new SecretNetworkClient({}),
identity: null,
})
} else {
Expand Down
5 changes: 5 additions & 0 deletions packages/scrt/scrt.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,11 @@ export const chainIds = {
testnet: 'pulsar-3',
}

export function connect (...args: Parameters<typeof ScrtChain["connect"]>) {
if (!args[0]) args[0] = {} as any
return ScrtChain.connect(...args)
}

/** See https://docs.scrt.network/secret-network-documentation/development/resources-api-contract-addresses/connecting-to-the-network/mainnet-secret-4#api-endpoints */
export const mainnets = new Set([
'https://lcd.mainnet.secretsaturn.net',
Expand Down
119 changes: 64 additions & 55 deletions test/checklist.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#!/usr/bin/env -S node --import @ganesha/esbuild

import { Console, colors, bold } from '@hackbg/logs'
import { Agent } from '../src/Agent'
import * as SN from '@fadroma/scrt'
import * as CW from '@fadroma/cw'
import * as Namada from '@fadroma/namada'
Expand All @@ -11,16 +12,22 @@ const console = new Console('Checklist')
const OK = colors.black.bgGreen // ok
const NO = colors.black.bgRed // test fails
const NI = colors.black.bgYellow // not implemented
const NA = colors.black.bgBlue // not applicable
const NA = colors.black.bgGray // not applicable

const platforms = { SN, CW, Namada, OCI }

let connectOptions = {}

const tests: Array<[string, Function]> = [

["connect", (platform: any) => {
if (platform["connect"]) return OK
}],

["mocknet", (platform: any) => {
if (platform["mocknet"]) return OK
}],

["devnet", (platform: any) => {
if (platform["devnet"]) return OK
}],
Expand All @@ -37,86 +44,104 @@ const tests: Array<[string, Function]> = [
if (platform["Chain"]) return OK
}],

["Chain#getConnection", async (platform: any) => {
const chain = await platform.connect()
if (await chain.getConnection()) return OK
}],

["Chain#height", async (platform: any) => {
const Chain = platform["Chain"]
const chain = new Chain({})
if (platform === OCI) return NA
const chain = await platform.connect()
if (await chain["height"]) return OK
}],

["Chain#nextBlock", async (platform: any) => {
const Chain = platform["Chain"]
const chain = new Chain({})
if (platform === OCI) return NA
const chain = await platform.connect()
if (await chain["nextBlock"]) return OK
}],

["Chain#fetchBlock", async (platform: any) => {
const Chain = platform["Chain"]
const chain = new Chain({})
if (await chain["nextBlock"]) return OK
if (platform === OCI) return NA
const chain = await platform.connect()
if (await chain.fetchBlock()) return OK
}],

["Chain#fetchBalance", async (platform: any) => {
const Chain = platform["Chain"]
const chain = new Chain({})
if (platform === OCI) return NA
const chain = await platform.connect()
if (await chain.fetchBalance()) return OK
}],

["Chain#fetchCodeInfo", async (platform: any) => {
const Chain = platform["Chain"]
const chain = new Chain({})
const chain = await platform.connect()
if (await chain.fetchCodeInfo()) return OK
}],

["Chain#fetchCodeInstances", async (platform: any) => {
const Chain = platform["Chain"]
const chain = new Chain({})
const chain = await platform.connect()
if (await chain.fetchCodeInstances()) return OK
}],

["Chain#fetchContractInfo", async (platform: any) => {
const Chain = platform["Chain"]
const chain = new Chain({})
const chain = await platform.connect()
if (await chain.fetchContractInfo()) return OK
}],

["Chain#query", async (platform: any) => {
const Chain = platform["Chain"]
const chain = new Chain({})
const chain = await platform.connect()
if (await chain.query()) return OK
}],

["Agent", async (platform: any) => {
if (platform["Agent"]) return OK
["Chain#authenticate", async (platform: any) => {
if (platform === Namada) return NA
const chain = await platform.connect()
const agent = await chain.authenticate()
if (agent instanceof Agent) return OK
}],

["Agent#getConnection", async (platform: any) => {
const Agent = platform["Chain"]
const agent = new Agent({})
if (platform === Namada) return NA
const chain = await platform.connect()
const agent = await chain.authenticate()
if (await agent.getConnection()) return OK
}],

["Agent#fetchBalance", async (platform: any) => {
const Agent = platform["Chain"]
const agent = new Agent({})
if (platform === Namada) return NA
if (platform === OCI) return NA
const chain = await platform.connect()
const agent = await chain.authenticate()
if (await agent.fetchBalance()) return OK
}],

["Agent#send", async (platform: any) => {
const Agent = platform["Chain"]
const agent = new Agent({})
if (platform === Namada) return NA
if (platform === OCI) return NA
const chain = await platform.connect()
const agent = await chain.authenticate()
if (await agent.send()) return OK
}],

["Agent#upload", async (platform: any) => {
const Agent = platform["Chain"]
const agent = new Agent({})
if (await agent.upload()) return OK
if (platform === Namada) return NA
const chain = await platform.connect()
const agent = await chain.authenticate()
if (await agent.upload({})) return OK
}],

["Agent#instantiate", async (platform: any) => {
const Agent = platform["Chain"]
const agent = new Agent({})
if (await agent.instantiate()) return OK
if (platform === Namada) return NA
const chain = await platform.connect()
const agent = await chain.authenticate()
if (await agent.instantiate({ codeId: '1', label: 'foo' })) return OK
}],

["Agent#execute", async (platform: any) => {
if (platform === Namada) return NA
const chain = await platform.connect()
const agent = await chain.authenticate()
if (await agent.execute({ address: 'x' })) return OK
}],

]
Expand All @@ -127,14 +152,19 @@ const errors = []
for (const [feature, test] of tests) {
table += bold(feature.padEnd(25))
for (const [platformName, platform] of Object.entries(platforms)) {
connectOptions = {}
if (platform === CW) {
connectOptions = { bech32Prefix: 'test', coinType: '0' }
}
let color = NI
try {
color = await Promise.resolve(test(platform)) || color
} catch (e) {
} catch (e: any) {
e.message = `${platformName}: ${feature}: ${e.message}`
errors.push(e)
color = NO
}
table += color(' ' + platformName.padEnd(6) + ' ') + ' '
table += color(' ' + platformName + ' ') + ' '
}
table += '\n'
}
Expand All @@ -145,24 +175,3 @@ for (const error of errors) {
}

process.stdout.write(table)

// For SCRT, CW, Namada, OCI:
// - connect
// - devnet
// - testnet
// - mainnet
// - Chain
// - height
// - nextBlock
// - fetchBlock
// - fetchBalance
// - fetchCodeInfo
// - fetchCodeInstances
// - fetchContractInfo
// - query
// - Agent
// - getConnection
// - fetchBalance
// - send
// - upload
// - instantiate

0 comments on commit 49a6e1b

Please sign in to comment.