-
Notifications
You must be signed in to change notification settings - Fork 257
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
serialization tests for operations. (#775)
- Loading branch information
Showing
17 changed files
with
301 additions
and
11 deletions.
There are no files selected for viewing
52 changes: 52 additions & 0 deletions
52
packages/common/evmUtils/src/operations/token/getWalletTokenTransfersOperation.test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
48 changes: 48 additions & 0 deletions
48
packages/common/evmUtils/src/operations/utils/runContractFunctionOperation.test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
31 changes: 31 additions & 0 deletions
31
packages/common/solUtils/src/operations/account/getBalanceOperation.test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
31 changes: 31 additions & 0 deletions
31
packages/common/solUtils/src/operations/account/getNFTsOperation.test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
31 changes: 31 additions & 0 deletions
31
packages/common/solUtils/src/operations/account/getPortfolioOperation.test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
31 changes: 31 additions & 0 deletions
31
packages/common/solUtils/src/operations/account/getSPLOperation.test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
31 changes: 31 additions & 0 deletions
31
packages/common/solUtils/src/operations/nft/getNFTMetadataOperation.test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
31 changes: 31 additions & 0 deletions
31
packages/common/solUtils/src/operations/token/getTokenPriceOperation.test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.