Skip to content

Commit

Permalink
Merge pull request #72 from nightly-labs/remove-env
Browse files Browse the repository at this point in the history
Remove process.env from bundles
  • Loading branch information
awojciak authored Nov 8, 2023
2 parents 6db92c1 + 0062812 commit 53747e7
Show file tree
Hide file tree
Showing 23 changed files with 189 additions and 184 deletions.
3 changes: 2 additions & 1 deletion sdk/apps/base/src/app.test.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { assert, beforeAll, beforeEach, describe, expect, test, vi } from 'vitest'
import { BaseApp } from './app'
import { smartDelay, testAppBaseInitialize, testClientBaseInitialize } from './utils'
import { testAppBaseInitialize, testClientBaseInitialize } from './testUtils'
import { smartDelay } from '../../../commonTestUtils'
import { BaseClient, Connect } from './client'
// Edit an assertion and save to see HMR in action
describe('Base App tests', () => {
Expand Down
3 changes: 2 additions & 1 deletion sdk/apps/base/src/client.test.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { assert, beforeAll, beforeEach, describe, expect, test, vi } from 'vitest'
import { BaseApp } from './app'
import { sleep, smartDelay, testAppBaseInitialize, testClientBaseInitialize } from './utils'
import { testAppBaseInitialize, testClientBaseInitialize } from './testUtils'
import { smartDelay } from '../../../commonTestUtils'
import { BaseClient, Connect } from './client'
import { ContentType, MessageToSign, TransactionToSign } from './content'
import { SignedMessage, SignedTransaction } from './responseContent'
Expand Down
6 changes: 4 additions & 2 deletions sdk/apps/base/src/http-client.test.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import { assert, beforeAll, beforeEach, describe, expect, test, vi } from 'vitest'
import { BaseApp } from './app'
import { RELAY_ENDPOINT, getRandomId, smartDelay, testAppBaseInitialize } from './utils'
import { getRandomId } from './utils'
import { testAppBaseInitialize } from './testUtils'
import { smartDelay, TEST_RELAY_ENDPOINT } from '../../../commonTestUtils'
import { Connect } from './client'
import { MessageToSign, TransactionToSign } from './content'
import { SignedMessage, SignedTransaction } from './responseContent'
Expand All @@ -20,7 +22,7 @@ describe('Http Base Client tests', () => {
expect(baseApp).toBeDefined()
assert(baseApp.sessionId !== '')

client = new HttpBaseClient({ url: RELAY_ENDPOINT, clientId: clientId })
client = new HttpBaseClient({ url: TEST_RELAY_ENDPOINT, clientId: clientId })
})
test('#getInfo()', async () => {
const info = await client.getInfo(baseApp.sessionId)
Expand Down
9 changes: 7 additions & 2 deletions sdk/apps/base/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,10 @@ export * from './content'
export * from './deeplinks'
export * from './http-client'
export * from './responseContent'
export { getRandomId, getWalletsMetadata, sleep, RELAY_ENDPOINT, smartDelay, getSessionIdLocalStorageKey } from './utils'
export * from './initializeTypes'
export {
getRandomId,
getWalletsMetadata,
RELAY_ENDPOINT,
getSessionIdLocalStorageKey
} from './utils'
export * from './initializeTypes'
3 changes: 2 additions & 1 deletion sdk/apps/base/src/multiple-app.test.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { describe, expect, test, vi } from 'vitest'
import { BaseApp } from './app'
import { smartDelay, testAppBaseInitialize, testClientBaseInitialize } from './utils'
import { testAppBaseInitialize, testClientBaseInitialize } from './testUtils'
import { smartDelay } from '../../../commonTestUtils'
import { BaseClient, Connect } from './client'
import { MessageToSign } from './content'
import { SignedMessage } from './responseContent'
Expand Down
3 changes: 2 additions & 1 deletion sdk/apps/base/src/persist-app.test.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import { assert, describe, expect, test, vi } from 'vitest'
import { BaseApp } from './app'
import { BaseClient, Connect } from './client'
import { smartDelay, testAppBaseInitialize, testClientBaseInitialize } from './utils'
import { testAppBaseInitialize, testClientBaseInitialize } from './testUtils'
import { smartDelay } from '../../../commonTestUtils'
// Edit an assertion and save to see HMR in action
describe('Base App tests', () => {
test('persistent session', async () => {
Expand Down
21 changes: 21 additions & 0 deletions sdk/apps/base/src/testUtils.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import { TEST_RELAY_ENDPOINT } from '../../../commonTestUtils'
import { AppBaseInitialize, ClientBaseInitialize } from './initializeTypes'

export const testAppBaseInitialize: AppBaseInitialize = {
appMetadata: {
additionalInfo: 'test-additional-info',
description: 'test-app-description',
icon: 'test-app-icon',
name: 'test-app-name'
},
network: 'test-network',
persistent: false,
persistentSessionId: undefined,
timeout: undefined,
url: TEST_RELAY_ENDPOINT
}

export const testClientBaseInitialize: ClientBaseInitialize = {
timeout: undefined,
url: TEST_RELAY_ENDPOINT
}
37 changes: 2 additions & 35 deletions sdk/apps/base/src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,44 +2,11 @@ import { v4 as uuidv4 } from 'uuid'
import { getStorage, ILocalStorage } from 'isomorphic-localstorage'
import { WalletMetadata } from '../../../bindings/WalletMetadata'
import { fetch } from 'cross-fetch'
import { AppBaseInitialize, ClientBaseInitialize } from './initializeTypes'

export const getRandomId = () => uuidv4()
export function sleep(ms: number) {
return new Promise((resolve) => setTimeout(resolve, ms))
}
export const RELAY_ENDPOINT = process.env.PRODUCTION
? 'https://nc2.nightly.app'
: 'http://127.0.0.1:6969'
export const testAppBaseInitialize: AppBaseInitialize = {
appMetadata: {
additionalInfo: 'test-additional-info',
description: 'test-app-description',
icon: 'test-app-icon',
name: 'test-app-name'
},
network: 'test-network',
persistent: false,
persistentSessionId: undefined,
timeout: undefined,
url: RELAY_ENDPOINT
}
export const testClientBaseInitialize: ClientBaseInitialize = {
timeout: undefined,
url: RELAY_ENDPOINT
}

export const smartDelay = async (ms?: number) => {
if (process.env.PRODUCTION) {
await sleep(ms || 100)
} else {
if (process.env.IS_CI) {
await sleep(ms || 100)
} else {
await sleep(ms || 5)
}
}
}
export const RELAY_ENDPOINT = 'https://nc2.nightly.app'

export const getWalletsMetadata = async (
url?: string,
network?: string
Expand Down
7 changes: 4 additions & 3 deletions sdk/apps/polkadot/src/e2e.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { ContentType, RELAY_ENDPOINT, smartDelay } from '@nightlylabs/nightly-connect-base'
import { ContentType } from '@nightlylabs/nightly-connect-base'
import { ApiPromise, WsProvider } from '@polkadot/api'
import { Keyring } from '@polkadot/keyring'
import { SignerPayloadRaw } from '@polkadot/types/types'
Expand All @@ -7,8 +7,9 @@ import { cryptoWaitReady, decodeAddress, signatureVerify } from '@polkadot/util-
import { assert, beforeAll, beforeEach, describe, expect, test } from 'vitest'
import { AppPolkadot } from './app'
import { ClientPolkadot, Connect } from './client'
import { TEST_APP_INITIALIZE } from './utils'
import { TEST_APP_INITIALIZE } from './testUtils'
import { SignTransactionsPolkadotRequest } from './requestTypes'
import { smartDelay, TEST_RELAY_ENDPOINT } from '../../../commonTestUtils'

// Edit an assertion and save to see HMR in action
const alice_keypair = new Keyring()
Expand All @@ -26,7 +27,7 @@ describe('Base Client tests', () => {
app = await AppPolkadot.build(TEST_APP_INITIALIZE)
expect(app).toBeDefined()
assert(app.sessionId !== '')
client = await ClientPolkadot.create({ url: RELAY_ENDPOINT }, TEST_APP_INITIALIZE.network)
client = await ClientPolkadot.create({ url: TEST_RELAY_ENDPOINT }, TEST_APP_INITIALIZE.network)
provider = new WsProvider('wss://ws.test.azero.dev/')
polkadotApi = await ApiPromise.create({
provider
Expand Down
12 changes: 4 additions & 8 deletions sdk/apps/polkadot/src/http-e2e.test.ts
Original file line number Diff line number Diff line change
@@ -1,19 +1,15 @@
import {
ContentType,
RELAY_ENDPOINT,
getRandomId,
smartDelay
} from '@nightlylabs/nightly-connect-base'
import { ContentType, getRandomId } from '@nightlylabs/nightly-connect-base'
import { assert, beforeAll, beforeEach, describe, expect, test } from 'vitest'
import { AppPolkadot } from './app'
import { TEST_APP_INITIALIZE } from './utils'
import { TEST_APP_INITIALIZE } from './testUtils'

import { ApiPromise, WsProvider } from '@polkadot/api'
import Keyring from '@polkadot/keyring'
import { SignerPayloadRaw } from '@polkadot/types/types'
import { u8aToHex } from '@polkadot/util'
import { decodeAddress, signatureVerify } from '@polkadot/util-crypto'
import { HttpClientPolkadot, HttpConnect } from './http-client'
import { smartDelay, TEST_RELAY_ENDPOINT } from '../../../commonTestUtils'

// Edit an assertion and save to see HMR in action
const alice_keypair = new Keyring()
Expand All @@ -30,7 +26,7 @@ describe('Base Client tests', () => {
app = await AppPolkadot.build(TEST_APP_INITIALIZE)
expect(app).toBeDefined()
assert(app.sessionId !== '')
client = new HttpClientPolkadot({ url: RELAY_ENDPOINT, clientId })
client = new HttpClientPolkadot({ url: TEST_RELAY_ENDPOINT, clientId })
provider = new WsProvider('wss://ws.test.azero.dev/')
polkadotApi = await ApiPromise.create({
provider
Expand Down
16 changes: 16 additions & 0 deletions sdk/apps/polkadot/src/testUtils.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import { AppPolkadotInitialize } from './app'
import { TEST_RELAY_ENDPOINT } from '../../../commonTestUtils'

export const TEST_APP_INITIALIZE: AppPolkadotInitialize = {
appMetadata: {
additionalInfo: 'test-polkadot-additional-info',
description: 'test-polkadot-app-description',
icon: 'test-polkadot-app-icon',
name: 'test-polkadot-app-name'
},
network: 'POLKADOT',
persistent: false,
persistentSessionId: undefined,
timeout: undefined,
url: TEST_RELAY_ENDPOINT
}
20 changes: 1 addition & 19 deletions sdk/apps/polkadot/src/utils.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import { ContentType, RELAY_ENDPOINT, RequestContent } from '@nightlylabs/nightly-connect-base'
import { AppPolkadotInitialize } from './app'
import { ContentType, RequestContent } from '@nightlylabs/nightly-connect-base'
import { SignerPayloadRaw, SignerPayloadJSON } from '@polkadot/types/types'
import {
SignTransactionsPolkadotRequest,
Expand All @@ -8,23 +7,6 @@ import {
PolkadotRequest
} from './requestTypes'

export const TEST_APP_INITIALIZE: AppPolkadotInitialize = {
appMetadata: {
additionalInfo: 'test-polkadot-additional-info',
description: 'test-polkadot-app-description',
icon: 'test-polkadot-app-icon',
name: 'test-polkadot-app-name'
},
network: 'POLKADOT',
persistent: false,
persistentSessionId: undefined,
timeout: undefined,
url: RELAY_ENDPOINT
}
export const sleep = (ms: number) => {
return new Promise((resolve) => setTimeout(resolve, ms))
}

export const parseRequest = (request: RequestContent, sessionId: string): PolkadotRequest => {
switch (request.content.type) {
case ContentType.SignTransactions: {
Expand Down
8 changes: 5 additions & 3 deletions sdk/apps/solana/src/e2e.test.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
import { Keypair, LAMPORTS_PER_SOL, SystemProgram, Transaction } from '@solana/web3.js'
import { Connect, ContentType, RELAY_ENDPOINT, smartDelay } from '@nightlylabs/nightly-connect-base'
import { Connect, ContentType } from '@nightlylabs/nightly-connect-base'
import { sha256 } from 'js-sha256'
import nacl from 'tweetnacl'
import { assert, beforeAll, beforeEach, describe, expect, test } from 'vitest'
import { AppSolana } from './app'
import { ClientSolana } from './client'
import { SOLANA_NETWORK, TEST_APP_INITIALIZE } from './utils'
import { SOLANA_NETWORK } from './utils'
import { TEST_APP_INITIALIZE } from './testUtils'
import { SignTransactionsSolanaRequest } from './requestTypes'
import { smartDelay, TEST_RELAY_ENDPOINT } from '../../../commonTestUtils'

// Edit an assertion and save to see HMR in action
const alice_keypair = Keypair.generate()
Expand All @@ -17,7 +19,7 @@ describe('Base Client tests', () => {
app = await AppSolana.build(TEST_APP_INITIALIZE)
expect(app).toBeDefined()
assert(app.sessionId !== '')
client = await ClientSolana.create({ url: RELAY_ENDPOINT })
client = await ClientSolana.create({ url: TEST_RELAY_ENDPOINT })
})
beforeEach(async () => {
await smartDelay()
Expand Down
14 changes: 5 additions & 9 deletions sdk/apps/solana/src/http-e2e.test.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,11 @@
import { assert, beforeAll, beforeEach, describe, expect, test } from 'vitest'
import { AppSolana } from './app'
import { SOLANA_NETWORK, TEST_APP_INITIALIZE } from './utils'
import {
Connect,
getRandomId,
RELAY_ENDPOINT,
smartDelay,
ContentType
} from '@nightlylabs/nightly-connect-base'
import { SOLANA_NETWORK } from './utils'
import { TEST_APP_INITIALIZE } from './testUtils'
import { Connect, getRandomId, ContentType } from '@nightlylabs/nightly-connect-base'
import { Keypair, LAMPORTS_PER_SOL, SystemProgram, Transaction } from '@solana/web3.js'
import { HttpClientSolana } from './http-client'
import { smartDelay, TEST_RELAY_ENDPOINT } from '../../../commonTestUtils'

// Edit an assertion and save to see HMR in action
const alice_keypair = Keypair.generate()
Expand All @@ -21,7 +17,7 @@ describe('Base Client tests', () => {
app = await AppSolana.build(TEST_APP_INITIALIZE)
expect(app).toBeDefined()
assert(app.sessionId !== '')
client = new HttpClientSolana({ url: RELAY_ENDPOINT, clientId })
client = new HttpClientSolana({ url: TEST_RELAY_ENDPOINT, clientId })
})
beforeEach(async () => {
await smartDelay()
Expand Down
18 changes: 18 additions & 0 deletions sdk/apps/solana/src/testUtils.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import { AppSolanaInitialize } from './utils'
import { TEST_RELAY_ENDPOINT } from '../../../commonTestUtils'

export const TEST_APP_INITIALIZE: AppSolanaInitialize = {
appMetadata: {
additionalInfo: 'test-solana-additional-info',
description: 'test-solana-app-description',
icon: 'test-solana-app-icon',
name: 'test-solana-app-name'
},
persistent: false,
persistentSessionId: undefined,
timeout: undefined,
url: TEST_RELAY_ENDPOINT
}
export function sleep(ms: number) {
return new Promise((resolve) => setTimeout(resolve, ms))
}
23 changes: 1 addition & 22 deletions sdk/apps/solana/src/utils.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,4 @@
import {
AppBaseInitialize,
ContentType,
RELAY_ENDPOINT,
RequestContent
} from '@nightlylabs/nightly-connect-base'
import { AppBaseInitialize, ContentType, RequestContent } from '@nightlylabs/nightly-connect-base'
import {
CustomSolanaRequest,
SignMessagesSolanaRequest,
Expand All @@ -16,22 +11,6 @@ export type AppSolanaInitialize = Omit<AppBaseInitialize, 'network'>

export const SOLANA_NETWORK = 'Solana'

export const TEST_APP_INITIALIZE: AppSolanaInitialize = {
appMetadata: {
additionalInfo: 'test-solana-additional-info',
description: 'test-solana-app-description',
icon: 'test-solana-app-icon',
name: 'test-solana-app-name'
},
persistent: false,
persistentSessionId: undefined,
timeout: undefined,
url: RELAY_ENDPOINT
}
export function sleep(ms: number) {
return new Promise((resolve) => setTimeout(resolve, ms))
}

export const parseRequest = (request: RequestContent, sessionId: string): SolanaRequest => {
switch (request.content.type) {
case ContentType.SignTransactions: {
Expand Down
16 changes: 6 additions & 10 deletions sdk/apps/sui/src/e2e.test.ts
Original file line number Diff line number Diff line change
@@ -1,23 +1,19 @@
import { Connect, ContentType, RELAY_ENDPOINT, smartDelay } from '@nightlylabs/nightly-connect-base'
import { Connect, ContentType } from '@nightlylabs/nightly-connect-base'
import { assert, beforeAll, beforeEach, describe, expect, test, vi } from 'vitest'
import { AppSui } from './app'
import { ClientSui } from './client'
import { signTransactionBlock, SUI_NETWORK, TEST_APP_INITIALIZE } from './utils'
import { signTransactionBlock, SUI_NETWORK } from './utils'
import { TEST_APP_INITIALIZE } from './testUtils'
import { fromB64, toB64 } from '@mysten/sui.js/utils'
import { TransactionBlock } from '@mysten/sui.js/transactions'
import { Ed25519Keypair } from '@mysten/sui.js/keypairs/ed25519'
import { verifyPersonalMessage, verifyTransactionBlock } from '@mysten/sui.js/verify'
import {
IntentScope,
messageWithIntent,
parseSerializedSignature,
toSerializedSignature
} from '@mysten/sui.js/cryptography'
import { blake2b } from '@noble/hashes/blake2b'
import { parseSerializedSignature, toSerializedSignature } from '@mysten/sui.js/cryptography'
import { fetch } from 'cross-fetch'
import { WalletAccount } from '@mysten/wallet-standard'
import { hexToBytes } from '@noble/hashes/utils'
import { SignTransactionsSuiRequest } from './requestTypes'
import { smartDelay, TEST_RELAY_ENDPOINT } from '../../../commonTestUtils'

global.fetch = fetch

Expand All @@ -42,7 +38,7 @@ describe('SUI client tests', () => {
app = await AppSui.build(TEST_APP_INITIALIZE)
expect(app).toBeDefined()
assert(app.sessionId !== '')
client = await ClientSui.create({ url: RELAY_ENDPOINT })
client = await ClientSui.create({ url: TEST_RELAY_ENDPOINT })
})
beforeEach(async () => {
await smartDelay()
Expand Down
Loading

0 comments on commit 53747e7

Please sign in to comment.