Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[explorer] Convert some tests to localnet tests #4580

Merged
merged 4 commits into from
Sep 14, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions explorer/client/cypress/e2e/localnet/address.cy.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
// Copyright (c) 2022, Mysten Labs, Inc.
// SPDX-License-Identifier: Apache-2.0

Cypress.config('baseUrl', 'http://localhost:3000');

describe('Address', () => {
it('can be directly visted', () => {
cy.task('faucet').then((address) => {
cy.visit(`/addresses/${address}`);
cy.get('#addressID').contains(address);
});
});
});
41 changes: 41 additions & 0 deletions explorer/client/cypress/e2e/localnet/objects.cy.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
// Copyright (c) 2022, Mysten Labs, Inc.
// SPDX-License-Identifier: Apache-2.0

Cypress.config('baseUrl', 'http://localhost:3000');

describe('Objects', () => {
it('can be reached through URL', () => {
cy.task('faucet')
.then((address) => cy.task('mint', address))
.then(({ effects }) => {
const { objectId } = effects.created![0].reference;
cy.visit(`/objects/${objectId}`);
cy.get('#objectID').contains(objectId);
});
});

it('displays an error when no objects', () => {
cy.visit(`/objects/fakeAddress`);
cy.get('#errorResult');
});

describe('Owned Objects', () => {
it('link going from address to object and back', () => {
cy.task('faucet')
.then((address) => cy.task('mint', address))
.then(({ certificate, effects }) => {
const address = certificate.data.sender;
const [nft] = effects.created!;
cy.visit(`/addresses/${address}`);

// Find a reference to the NFT:
cy.contains(nft.reference.objectId.slice(0, 4)).click();
cy.get('#objectID').contains(nft.reference.objectId);

// Find a reference to the owning address:
cy.contains(address).click();
cy.get('#addressID').contains(address);
});
});
});
});
11 changes: 11 additions & 0 deletions explorer/client/cypress/e2e/localnet/search.cy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,15 @@ describe('search', () => {
cy.url().should('include', `/addresses/${address}`);
});
});

it('can search for objects', () => {
cy.task('faucet')
.then((address) => cy.task('mint', address))
.then(({ effects }) => {
const { objectId } = effects.created![0].reference;
cy.visit('/');
cy.get('[data-testid=search]').type(objectId).type('{enter}');
cy.url().should('include', `/objects/${objectId}`);
});
});
});
72 changes: 0 additions & 72 deletions explorer/client/cypress/e2e/static/e2e.cy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,6 @@ const nftObject = (num: number) => `div#ownedObjects > div:nth-child(${num}) a`;
const ownerButton = 'td#owner > div > div';

// Standardized expectations:
const expectHome = () => {
cy.get(mainBodyCSS).invoke('attr', 'data-testid').should('eq', 'home-page');
};

const expectErrorResult = () => {
cy.get(mainBodyCSS).invoke('attr', 'id').should('eq', 'errorResult');
};
Expand All @@ -23,24 +19,6 @@ const searchText = (text: string) => {
};

describe('End-to-end Tests', () => {
describe('The Home Page', () => {
it('is the landing page', () => {
cy.visit('/');
expectHome();
});

it('is the redirect page', () => {
cy.visit('/apples');
expectHome();
});

it('has a go home button', () => {
cy.visit('/objects/CollectionObject');
cy.get('#homeBtn').click();
expectHome();
});
});

describe('Wrong Search', () => {
it('leads to error page', () => {
cy.visit('/');
Expand All @@ -49,48 +27,6 @@ describe('End-to-end Tests', () => {
});
});

describe('Object Results', () => {
const successObjectID = 'CollectionObject';
const problemObjectID = 'ProblemObject';

it('can be searched', () => {
cy.visit('/');
searchText(successObjectID);
cy.get('#objectID').contains(successObjectID);
});

it('can be reached through URL', () => {
cy.visit(`/objects/${successObjectID}`);
cy.get('#objectID').contains(successObjectID);
});

it('can have missing data', () => {
cy.visit(`/objects/${problemObjectID}`);
expectErrorResult();
});
});

describe('Address Results', () => {
const successAddressID = 'receiverAddress';
const noObjectsAddressID = 'senderAddress';

it('can be searched', () => {
cy.visit('/');
searchText(successAddressID);
cy.get('#addressID').contains(successAddressID);
});

it('can be reached through URL', () => {
cy.visit(`/addresses/${successAddressID}`);
cy.get('#addressID').contains(successAddressID);
});

it('displays error when no objects', () => {
cy.visit(`/objects/${noObjectsAddressID}`);
expectErrorResult();
});
});

describe('Transaction Results', () => {
const successID = 'Da4vHc9IwbvOYblE8LnrVsqXwryt2Kmms+xnJ7Zx5E4=';
it('can be searched', () => {
Expand All @@ -113,14 +49,6 @@ describe('End-to-end Tests', () => {
});

describe('Owned Objects have links that enable', () => {
it('going from address to object and back', () => {
cy.visit('/addresses/receiverAddress');
cy.get(nftObject(1)).click();
cy.get('#objectID').contains('player1');
cy.get(ownerButton).click();
cy.get('#addressID').contains('receiverAddress');
});

it('going from object to child object and back', () => {
cy.visit('/objects/player2');
cy.get(nftObject(1)).click();
Expand Down
31 changes: 30 additions & 1 deletion explorer/client/cypress/localnet.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,41 @@ import axios from 'axios';

// NOTE: We import out of the source directory here to work around an issue with Cypress not
// respecting tsconfig paths in the config file.
import { Ed25519Keypair, type Keypair } from '../../../sdk/typescript/src';
import {
Ed25519Keypair,
JsonRpcProvider,
RawSigner,
type Keypair,
} from '../../../sdk/typescript/src';

export async function createLocalnetTasks() {
const addressToKeypair = new Map<string, Keypair>();

return {
async mint(address: string) {
const keypair = addressToKeypair.get(address);
if (!keypair) {
throw new Error('missing keypair');
}
const provider = new JsonRpcProvider('http://localhost:5001');
const signer = new RawSigner(keypair, provider);

const tx = await signer.executeMoveCall({
packageObjectId: '0x2',
module: 'devnet_nft',
function: 'mint',
typeArguments: [],
arguments: [
'Example NFT',
'An example NFT.',
'ipfs://bafkreibngqhl3gaa7daob4i2vccziay2jjlp435cf66vhono7nrvww53ty',
],
gasBudget: 30000,
});

return tx;
},

async faucet() {
const keypair = Ed25519Keypair.generate();
const address = keypair.getPublicKey().toSuiAddress();
Expand Down
6 changes: 6 additions & 0 deletions explorer/client/cypress/support/commands.d.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,16 @@
// Copyright (c) 2022, Mysten Labs, Inc.
// SPDX-License-Identifier: Apache-2.0

/* eslint-disable @typescript-eslint/consistent-type-imports */

/// <reference types="cypress" />

declare namespace Cypress {
interface Chainable {
task(name: 'faucet', arg?: unknown): Chainable<string>;
task(
name: 'mint',
address?: string
): Chainable<import('@mysten/sui.js').SuiTransactionResponse>;
}
}