Skip to content

Commit

Permalink
test(e2e): repurpose blockfrost test suite for direct from client pro…
Browse files Browse the repository at this point in the history
…viders
  • Loading branch information
mkazlauskas committed Nov 14, 2024
1 parent b5c9f26 commit 6d711bf
Show file tree
Hide file tree
Showing 5 changed files with 59 additions and 30 deletions.
14 changes: 7 additions & 7 deletions .github/workflows/continuous-integration-blockfrost-e2e.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -10,20 +10,20 @@ env:
OGMIOS_URL: 'ws://localhost:1340/'
STAKE_POOL_CONNECTION_STRING: 'postgresql://postgres:doNoUseThisSecret!@localhost:5435/stake_pool'
STAKE_POOL_TEST_CONNECTION_STRING: 'postgresql://postgres:doNoUseThisSecret!@localhost:5435/stake_pool_test'
TEST_CLIENT_ASSET_PROVIDER: 'http'
TEST_CLIENT_ASSET_PROVIDER_PARAMS: '{"baseUrl":"http://localhost:4014/"}'
TEST_CLIENT_CHAIN_HISTORY_PROVIDER: 'http'
TEST_CLIENT_CHAIN_HISTORY_PROVIDER_PARAMS: '{"baseUrl":"http://localhost:4001/"}'
TEST_CLIENT_ASSET_PROVIDER: 'blockfrost'
TEST_CLIENT_ASSET_PROVIDER_PARAMS: '{"baseUrl":"http://blockfrost-ryo:3000"}'
TEST_CLIENT_CHAIN_HISTORY_PROVIDER: 'ws'
TEST_CLIENT_CHAIN_HISTORY_PROVIDER_PARAMS: '{"baseUrl":"http://localhost:4000/"}'
TEST_CLIENT_HANDLE_PROVIDER: 'http'
TEST_CLIENT_HANDLE_PROVIDER_PARAMS: '{"baseUrl":"http://localhost:4011/"}'
TEST_CLIENT_NETWORK_INFO_PROVIDER: 'ws'
TEST_CLIENT_NETWORK_INFO_PROVIDER_PARAMS: '{"baseUrl":"http://localhost:4000/"}'
TEST_CLIENT_REWARDS_PROVIDER: 'http'
TEST_CLIENT_REWARDS_PROVIDER_PARAMS: '{"baseUrl":"http://localhost:4001/"}'
TEST_CLIENT_REWARDS_PROVIDER_PARAMS: '{"baseUrl":"http://localhost:4000/"}'
TEST_CLIENT_TX_SUBMIT_PROVIDER: 'http'
TEST_CLIENT_TX_SUBMIT_PROVIDER_PARAMS: '{"baseUrl":"http://localhost:4000/"}'
TEST_CLIENT_UTXO_PROVIDER: 'http'
TEST_CLIENT_UTXO_PROVIDER_PARAMS: '{"baseUrl":"http://localhost:4001/"}'
TEST_CLIENT_UTXO_PROVIDER: 'ws'
TEST_CLIENT_UTXO_PROVIDER_PARAMS: '{"baseUrl":"http://localhost:4000/"}'
TEST_CLIENT_STAKE_POOL_PROVIDER: 'http'
TEST_CLIENT_STAKE_POOL_PROVIDER_PARAMS: '{"baseUrl":"http://localhost:4000/"}'
WS_PROVIDER_URL: 'http://localhost:4100/ws'
Expand Down
20 changes: 12 additions & 8 deletions packages/e2e/.env.example
Original file line number Diff line number Diff line change
Expand Up @@ -66,11 +66,15 @@ STAKE_POOL_PROJECTOR_URL='http://localhost:4002/'
NETWORK_SPEED=fast

# to run tests against local blockfrost
# Blockfrost secrets
#BLOCKFROST_CUSTOM_BACKEND_URL='http://blockfrost-ryo:3000'
#ASSET_PROVIDER: 'blockfrost'
#UTXO_PROVIDER: 'blockfrost'
#CHAIN_HISTORY_PROVIDER: 'blockfrost'
#REWARDS_PROVIDER: 'blockfrost'
#NETWORK_INFO_PROVIDER: 'blockfrost'
#TX_SUBMIT_PROVIDER: 'blockfrost'
TEST_CLIENT_ASSET_PROVIDER='blockfrost'
TEST_CLIENT_ASSET_PROVIDER_PARAMS='{"baseUrl":"http://localhost:3015"}'
#TEST_CLIENT_UTXO_PROVIDER='blockfrost'
#TEST_UTXO_PROVIDER_PARAMS='{"baseUrl":"http://localhost:3015"}'
#TEST_CLIENT_CHAIN_HISTORY_PROVIDER='blockfrost'
#TEST_CLIENT_CHAIN_HISTORY_PROVIDER_PARAMS='{"baseUrl":"http://localhost:3015"}'
#TEST_CLIENT_REWARDS_PROVIDER='blockfrost'
#TEST_REWARDS_PROVIDER_PARAMS='{"baseUrl":"http://localhost:3015"}'
#TEST_CLIENT_NETWORK_INFO_PROVIDER='blockfrost'
#TEST_NETWORK_INFO_PROVIDER_PARAMS='{"baseUrl":"http://localhost:3015"}'
#TEST_CLIENT_TX_SUBMIT_PROVIDER='blockfrost'
#TEST_TX_SUBMIT_PROVIDER_PARAMS='{"baseUrl":"http://localhost:3015"}'
16 changes: 16 additions & 0 deletions packages/e2e/src/factories.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@ import {
util
} from '@cardano-sdk/key-management';
import {
BlockfrostAssetProvider,
BlockfrostClient,
CardanoWsClient,
assetInfoHttpProvider,
chainHistoryHttpProvider,
Expand Down Expand Up @@ -66,6 +68,7 @@ const HTTP_PROVIDER = 'http';
const OGMIOS_PROVIDER = 'ogmios';
const STUB_PROVIDER = 'stub';
const WS_PROVIDER = 'ws';
const BLOCKFROST_PROVIDER = 'blockfrost';

const MISSING_URL_PARAM = 'Missing URL';

Expand Down Expand Up @@ -130,6 +133,19 @@ assetProviderFactory.register(HTTP_PROVIDER, async (params: any, logger: Logger)
});
});

assetProviderFactory.register(BLOCKFROST_PROVIDER, async (params: any, logger): Promise<AssetProvider> => {
if (params.baseUrl === undefined) throw new Error(`${BlockfrostAssetProvider.name}: ${MISSING_URL_PARAM}`);

return new Promise<AssetProvider>(async (resolve) => {
resolve(
new BlockfrostAssetProvider(
new BlockfrostClient({ baseUrl: params.baseUrl }, { rateLimiter: { schedule: (task) => task() } }),
logger
)
);
});
});

chainHistoryProviderFactory.register(
HTTP_PROVIDER,
async (params: any, logger: Logger): Promise<ChainHistoryProvider> => {
Expand Down
16 changes: 13 additions & 3 deletions packages/e2e/test/blockfrost/getAsset.test.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,21 @@
import { BlockfrostAssetProvider } from '@cardano-sdk/cardano-services-client';
import { Cardano } from '@cardano-sdk/core';
import { assetProviderFactory, getEnv, walletVariables } from '../../src';
import { logger } from '@cardano-sdk/util-dev';
import { util } from '@cardano-sdk/cardano-services';

const env = getEnv(walletVariables);

describe('BlockfrostAssetProvider', () => {
beforeAll(() => {
if (env.TEST_CLIENT_ASSET_PROVIDER !== 'blockfrost')
throw new Error('TEST_CLIENT_ASSET_PROVIDER must be "blockfrost" to run these tests');
});

test('getAsset', async () => {
const assetProvider = new BlockfrostAssetProvider(util.getBlockfrostClient(), logger);
const assetProvider = await assetProviderFactory.create(
'blockfrost',
env.TEST_CLIENT_ASSET_PROVIDER_PARAMS,
logger
);
const asset = await assetProvider.getAsset({
assetId: Cardano.AssetId(
'b27160f0c50a9cf168bf945dcbfcabbfbee5c7a801e7b467093b41534d6574616c4d6f6e7374657230303036'
Expand Down
23 changes: 11 additions & 12 deletions packages/e2e/test/wallet_epoch_0/PersonalWallet/nft.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -206,15 +206,14 @@ describe('PersonalWallet.assets/nft', () => {
nftMetadata: {
image: 'ipfs://some_hash1',
name: 'One',
otherProperties: new Map([['version', '1.0']]),
version: '1.0'
},
policyId,
// in case of repeated tests on the same network, total asset supply is not updated due to
// the limitation that asset info is not refreshed on wallet balance changes
quantity: expect.anything(),
supply: expect.anything(),
tokenMetadata: null
tokenMetadata: expect.anything()
});
expect(nfts.find((nft) => nft.assetId === assetIds[TOKEN_METADATA_1_INDEX])).toBeDefined();
});
Expand Down Expand Up @@ -246,15 +245,12 @@ describe('PersonalWallet.assets/nft', () => {
image: 'ipfs://somehash',
mediaType: 'image/png',
name: 'NFT with files',
otherProperties: new Map([
['id', '1'],
['version', '1.0']
]),
otherProperties: new Map([['id', '1']]),
version: '1.0'
} as Asset.NftMetadata,
policyId,
supply: expect.anything(),
tokenMetadata: null
tokenMetadata: expect.anything()
});
});

Expand Down Expand Up @@ -325,7 +321,7 @@ describe('PersonalWallet.assets/nft', () => {
metadatum.jsonToMetadatum({
image: ['ipfs://some_hash1'],
name: assetName,
version: '1.0'
version
})
]
])
Expand Down Expand Up @@ -377,18 +373,21 @@ describe('PersonalWallet.assets/nft', () => {
nftMetadata: {
image: 'ipfs://some_hash1',
name: assetName,
otherProperties: new Map([['version', '1.0']]),
version: '1.0'
version: `${version}.0`
},
policyId,
quantity: expect.anything(),
supply: expect.anything(),
tokenMetadata: null
tokenMetadata: expect.anything()
});
});

CIP0025Test('supports CIP-25 v1, assetName hex encoded', 'CIP-0025-v1-hex', 1, 'hex');
CIP0025Test('supports CIP-25 v1, assetName utf8 encoded', 'CIP-0025-v1-utf8', 1, 'utf8');
CIP0025Test('supports CIP-25 v2', 'CIP-0025-v2', 2);

// https://input-output-rnd.slack.com/archives/C06J663L2A2/p1731505470694659
env.TEST_CLIENT_ASSET_PROVIDER !== 'blockfrost'
? CIP0025Test('supports CIP-25 v2', 'CIP-0025-v2', 2)
: test.todo('"supports CIP-25 v2" test is disabled when running with Blockfrost asset provider');
});
});

0 comments on commit 6d711bf

Please sign in to comment.