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

serialization tests for operations. #775

Merged
merged 4 commits into from
Oct 26, 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
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
import MoralisCore from '@moralisweb3/core';
import { EvmAddress, EvmChain } from '../../dataTypes';
import { getWalletTokenTransfersOperation, GetWalletTokenTransfersRequest } from './getWalletTokenTransfersOperation';

describe('getWalletTokenTransfersOperation', () => {
let core: MoralisCore;

beforeAll(() => {
core = MoralisCore.create();
});

it('serializeRequest() serializes correctly and deserializeRequest() deserializes correctly', () => {
const address = '0xfB6916095ca1df60bB79Ce92cE3Ea74c37c5d359';
const chain = '0x10';

const request: Required<GetWalletTokenTransfersRequest> = {
address: EvmAddress.create(address, core),
chain: EvmChain.create(chain, core),
fromBlock: 10,
toBlock: 20,
fromDate: '2000-12-20',
toDate: '2000-12-25',
subdomain: 'test.com',
cursor: 'CURSOR1',
limit: 333,
};

const serializedRequest = getWalletTokenTransfersOperation.serializeRequest(request, core);

expect(serializedRequest.address).toBe(address);
expect(serializedRequest.chain).toBe(chain);
expect(serializedRequest.fromBlock).toBe(request.fromBlock);
expect(serializedRequest.toBlock).toBe(request.toBlock);
expect(serializedRequest.fromDate).toBe(request.fromDate);
expect(serializedRequest.toDate).toBe(request.toDate);
expect(serializedRequest.subdomain).toBe(request.subdomain);
expect(serializedRequest.cursor).toBe(request.cursor);
expect(serializedRequest.limit).toBe(request.limit);

const deserializedRequest = getWalletTokenTransfersOperation.deserializeRequest(serializedRequest, core);

expect((deserializedRequest.address as EvmAddress).checksum).toBe(address);
expect((deserializedRequest.chain as EvmChain).apiHex).toBe(chain);
expect(deserializedRequest.fromBlock).toBe(request.fromBlock);
expect(deserializedRequest.toBlock).toBe(request.toBlock);
expect(deserializedRequest.fromDate).toBe(request.fromDate);
expect(deserializedRequest.toDate).toBe(request.toDate);
expect(deserializedRequest.subdomain).toBe(request.subdomain);
expect(deserializedRequest.cursor).toBe(request.cursor);
expect(deserializedRequest.limit).toBe(request.limit);
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ export const getWalletTokenTransfersOperation: PaginatedOperation<

function getRequestUrlParams(request: GetWalletTokenTransfersRequest, core: Core) {
return {
address: String(request.address),
address: EvmAddress.create(request.address, core).lowercase,
chain: EvmChainResolver.resolve(request.chain, core).apiHex,
cursor: request.cursor,
limit: maybe(request.limit, String),
Expand Down Expand Up @@ -75,13 +75,15 @@ function deserializeResponse(

function serializeRequest(request: GetWalletTokenTransfersRequest, core: Core) {
return {
address: request.address.toString(),
address: EvmAddress.create(request.address, core).checksum,
chain: EvmChainResolver.resolve(request.chain, core).apiHex,
cursor: request.cursor,
toBlock: request.toBlock,
fromBlock: request.fromBlock,
fromDate: request.fromDate,
toDate: request.toDate,
subdomain: request.subdomain,
limit: request.limit,
};
}

Expand All @@ -97,5 +99,7 @@ function deserializeRequest(
fromBlock: jsonRequest.fromBlock,
fromDate: jsonRequest.fromDate,
toDate: jsonRequest.toDate,
subdomain: jsonRequest.subdomain,
limit: jsonRequest.limit,
};
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
import MoralisCore from '@moralisweb3/core';
import { EvmAddress, EvmChain } from '../../dataTypes';
import { runContractFunctionOperation, RunContractFunctionRequest } from './runContractFunctionOperation';

describe('runContractFunctionOperation', () => {
let core: MoralisCore;

beforeAll(() => {
core = MoralisCore.create();
});

it('serializeRequest() serializes correctly and deserializeRequest() deserializes correctly', () => {
const address = '0xfB6916095ca1df60bB79Ce92cE3Ea74c37c5d359';
const chain = '0x10';

const request: Required<RunContractFunctionRequest> = {
address: EvmAddress.create(address, core),
chain: EvmChain.create(chain, core),
functionName: 'myFunction',
params: { x: 1 },
abi: [
/* empty abi */
],
providerUrl: 'https://provider.com/url',
subdomain: 'my-domain.com',
};

const serializedRequest = runContractFunctionOperation.serializeRequest(request, core);

expect(serializedRequest.address).toBe(address);
expect(serializedRequest.chain).toBe(chain);
expect(serializedRequest.functionName).toBe(request.functionName);
expect(serializedRequest.params).toBe(request.params);
expect(serializedRequest.abi).toBe(request.abi);
expect(serializedRequest.providerUrl).toBe(request.providerUrl);
expect(serializedRequest.subdomain).toBe(request.subdomain);

const deserializedRequest = runContractFunctionOperation.deserializeRequest(serializedRequest, core);

expect((deserializedRequest.address as EvmAddress).checksum).toBe(address);
expect((deserializedRequest.chain as EvmChain).apiHex).toBe(chain);
expect(serializedRequest.functionName).toBe(request.functionName);
expect(serializedRequest.params).toBe(request.params);
expect(serializedRequest.abi).toBe(request.abi);
expect(serializedRequest.providerUrl).toBe(request.providerUrl);
expect(serializedRequest.subdomain).toBe(request.subdomain);
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ export const runContractFunctionOperation: Operation<

function getRequestUrlParams(request: RunContractFunctionRequest, core: Core) {
return {
address: EvmAddress.create(request.address, core).checksum,
address: EvmAddress.create(request.address, core).lowercase,
chain: EvmChainResolver.resolve(request.chain, core).apiHex,
functionName: request.functionName,
providerUrl: request.providerUrl,
Expand All @@ -71,7 +71,7 @@ function deserializeResponse(jsonResponse: RunContractFunctionJSONResponse) {

function serializeRequest(request: RunContractFunctionRequest, core: Core) {
return {
address: EvmAddress.create(request.address, core).toString(),
address: EvmAddress.create(request.address, core).checksum,
chain: EvmChainResolver.resolve(request.chain, core).apiHex,
functionName: request.functionName,
providerUrl: request.providerUrl,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
import MoralisCore from '@moralisweb3/core';
import { SolAddress, SolNetwork } from '../../dataTypes';
import { getBalanceOperation, GetBalanceRequest } from './getBalanceOperation';

describe('getBalanceOperation', () => {
let core: MoralisCore;

beforeAll(() => {
core = MoralisCore.create();
});

it('serializeRequest() serializes correctly and deserializeRequest() deserializes correctly', () => {
const address = '9WzDXwBbmkg8ZTbNMqUxvQRAyrZzDsGYdLVL9zYtAWWM';
const network = 'mainnet';

const request: Required<GetBalanceRequest> = {
address: SolAddress.create(address),
network: SolNetwork.create(network),
};

const serializedRequest = getBalanceOperation.serializeRequest(request, core);

expect(serializedRequest.address).toBe(address);
expect(serializedRequest.network).toBe(network);

const deserializedRequest = getBalanceOperation.deserializeRequest(serializedRequest, core);

expect((deserializedRequest.address as SolAddress).address).toBe(address);
expect((deserializedRequest.network as SolNetwork).network).toBe(network);
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ function deserializeResponse(jsonResponse: GetBalanceJSONResponse) {

function serializeRequest(request: GetBalanceRequest, core: Core) {
return {
address: request.address.toString(),
address: SolAddress.create(request.address).address,
network: SolNetworkResolver.resolve(request.network, core),
};
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
import MoralisCore from '@moralisweb3/core';
import { SolAddress, SolNetwork } from '../../dataTypes';
import { getNFTsOperation, GetNFTsRequest } from './getNFTsOperation';

describe('getNFTsOperation', () => {
let core: MoralisCore;

beforeAll(() => {
core = MoralisCore.create();
});

it('serializeRequest() serializes correctly and deserializeRequest() deserializes correctly', () => {
const address = '9WzDXwBbmkg8ZTbNMqUxvQRAyrZzDsGYdLVL9zYtAWWM';
const network = 'mainnet';

const request: Required<GetNFTsRequest> = {
address: SolAddress.create(address),
network: SolNetwork.create(network),
};

const serializedRequest = getNFTsOperation.serializeRequest(request, core);

expect(serializedRequest.address).toBe(address);
expect(serializedRequest.network).toBe(network);

const deserializedRequest = getNFTsOperation.deserializeRequest(serializedRequest, core);

expect((deserializedRequest.address as SolAddress).address).toBe(address);
expect((deserializedRequest.network as SolNetwork).network).toBe(network);
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ function deserializeResponse(jsonResponse: GetNFTsJSONResponse) {

function serializeRequest(request: GetNFTsRequest, core: Core) {
return {
address: request.address.toString(),
address: SolAddress.create(request.address).address,
network: SolNetworkResolver.resolve(request.network, core),
};
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
import MoralisCore from '@moralisweb3/core';
import { SolAddress, SolNetwork } from '../../dataTypes';
import { getPortfolioOperation, GetPortfolioRequest } from './getPortfolioOperation';

describe('getPortfolioOperation', () => {
let core: MoralisCore;

beforeAll(() => {
core = MoralisCore.create();
});

it('serializeRequest() serializes correctly and deserializeRequest() deserializes correctly', () => {
const address = '9WzDXwBbmkg8ZTbNMqUxvQRAyrZzDsGYdLVL9zYtAWWM';
const network = 'mainnet';

const request: Required<GetPortfolioRequest> = {
address: SolAddress.create(address),
network: SolNetwork.create(network),
};

const serializedRequest = getPortfolioOperation.serializeRequest(request, core);

expect(serializedRequest.address).toBe(address);
expect(serializedRequest.network).toBe(network);

const deserializedRequest = getPortfolioOperation.deserializeRequest(serializedRequest, core);

expect((deserializedRequest.address as SolAddress).address).toBe(address);
expect((deserializedRequest.network as SolNetwork).network).toBe(network);
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ function deserializeResponse(jsonResponse: GetPortfolioJSONResponse) {

function serializeRequest(request: GetPortfolioRequest, core: Core) {
return {
address: request.address.toString(),
address: SolAddress.create(request.address).address,
network: SolNetworkResolver.resolve(request.network, core),
};
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
import MoralisCore from '@moralisweb3/core';
import { SolAddress, SolNetwork } from '../../dataTypes';
import { getSPLOperation, GetSPLRequest } from './getSPLOperation';

describe('getSPLOperation', () => {
let core: MoralisCore;

beforeAll(() => {
core = MoralisCore.create();
});

it('serializeRequest() serializes correctly and deserializeRequest() deserializes correctly', () => {
const address = '9WzDXwBbmkg8ZTbNMqUxvQRAyrZzDsGYdLVL9zYtAWWM';
const network = 'mainnet';

const request: Required<GetSPLRequest> = {
address: SolAddress.create(address),
network: SolNetwork.create(network),
};

const serializedRequest = getSPLOperation.serializeRequest(request, core);

expect(serializedRequest.address).toBe(address);
expect(serializedRequest.network).toBe(network);

const deserializedRequest = getSPLOperation.deserializeRequest(serializedRequest, core);

expect((deserializedRequest.address as SolAddress).address).toBe(address);
expect((deserializedRequest.network as SolNetwork).network).toBe(network);
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ function deserializeResponse(jsonResponse: GetSPLJSONResponse) {

function serializeRequest(request: GetSPLRequest, core: Core) {
return {
address: request.address.toString(),
address: SolAddress.create(request.address).address,
network: SolNetworkResolver.resolve(request.network, core),
};
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
import MoralisCore from '@moralisweb3/core';
import { SolAddress, SolNetwork } from '../../dataTypes';
import { getNFTMetadataOperation, GetNFTMetadataRequest } from './getNFTMetadataOperation';

describe('getNFTMetadataOperation', () => {
let core: MoralisCore;

beforeAll(() => {
core = MoralisCore.create();
});

it('serializeRequest() serializes correctly and deserializeRequest() deserializes correctly', () => {
const address = '9WzDXwBbmkg8ZTbNMqUxvQRAyrZzDsGYdLVL9zYtAWWM';
const network = 'mainnet';

const request: Required<GetNFTMetadataRequest> = {
address: SolAddress.create(address),
network: SolNetwork.create(network),
};

const serializedRequest = getNFTMetadataOperation.serializeRequest(request, core);

expect(serializedRequest.address).toBe(address);
expect(serializedRequest.network).toBe(network);

const deserializedRequest = getNFTMetadataOperation.deserializeRequest(serializedRequest, core);

expect((deserializedRequest.address as SolAddress).address).toBe(address);
expect((deserializedRequest.network as SolNetwork).network).toBe(network);
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ function deserializeResponse(jsonResponse: GetNFTMetadataJSONResponse) {

function serializeRequest(request: GetNFTMetadataRequest, core: Core) {
return {
address: request.address.toString(),
address: SolAddress.create(request.address).address,
network: SolNetworkResolver.resolve(request.network, core),
};
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
import MoralisCore from '@moralisweb3/core';
import { SolAddress, SolNetwork } from '../../dataTypes';
import { getTokenPriceOperation, GetTokenPriceRequest } from './getTokenPriceOperation';

describe('getTokenPriceOperation', () => {
let core: MoralisCore;

beforeAll(() => {
core = MoralisCore.create();
});

it('serializeRequest() serializes correctly and deserializeRequest() deserializes correctly', () => {
const address = '9WzDXwBbmkg8ZTbNMqUxvQRAyrZzDsGYdLVL9zYtAWWM';
const network = 'mainnet';

const request: Required<GetTokenPriceRequest> = {
address: SolAddress.create(address),
network: SolNetwork.create(network),
};

const serializedRequest = getTokenPriceOperation.serializeRequest(request, core);

expect(serializedRequest.address).toBe(address);
expect(serializedRequest.network).toBe(network);

const deserializedRequest = getTokenPriceOperation.deserializeRequest(serializedRequest, core);

expect((deserializedRequest.address as SolAddress).address).toBe(address);
expect((deserializedRequest.network as SolNetwork).network).toBe(network);
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ function deserializeResponse(jsonResponse: GetTokenPriceJSONResponse) {

function serializeRequest(request: GetTokenPriceRequest, core: Core) {
return {
address: request.address.toString(),
address: SolAddress.create(request.address).address,
network: SolNetworkResolver.resolve(request.network, core),
};
}
Expand Down
Loading