diff --git a/__tests__/defaultProvider.test.ts b/__tests__/defaultProvider.test.ts index 3e4d0df0a..d39eaaa9d 100644 --- a/__tests__/defaultProvider.test.ts +++ b/__tests__/defaultProvider.test.ts @@ -1,10 +1,23 @@ -import { BlockNumber, GetBlockResponse, stark } from '../src'; +import { + BlockNumber, + DeclareContractResponse, + DeployContractResponse, + GetBlockResponse, + SequencerProvider, + stark, +} from '../src'; import { toBN } from '../src/utils/number'; -import { IS_DEVNET, compiledErc20, compiledOpenZeppelinAccount, getTestProvider } from './fixtures'; +import { + IS_DEVNET, + compiledErc20, + compiledOpenZeppelinAccount, + getTestProvider, + getTestRpcProvider, +} from './fixtures'; const { compileCalldata } = stark; -const provider = getTestProvider(); +const testProvider = getTestProvider(); describe('defaultProvider', () => { let exampleTransactionHash: string; @@ -15,25 +28,25 @@ describe('defaultProvider', () => { let exampleBlockHash!: string; beforeAll(async () => { - const { transaction_hash, contract_address } = await provider.deployContract({ + const { transaction_hash, contract_address } = await testProvider.deployContract({ contract: compiledErc20, }); - await provider.waitForTransaction(transaction_hash); + await testProvider.waitForTransaction(transaction_hash); exampleTransactionHash = transaction_hash; exampleContractAddress = contract_address; - exampleBlock = await provider.getBlock(); + exampleBlock = await testProvider.getBlock(); exampleBlockHash = exampleBlock.block_hash; exampleBlockNumber = exampleBlock.block_number; }); describe('endpoints', () => { test(`getBlock(blockHash=undefined, blockNumber=${exampleBlockNumber})`, () => { - return expect(provider.getBlock(exampleBlockNumber)).resolves.not.toThrow(); + return expect(testProvider.getBlock(exampleBlockNumber)).resolves.not.toThrow(); }); test(`getBlock(blockHash=${exampleBlockHash}, blockNumber=undefined)`, () => { - return expect(provider.getBlock(exampleBlockHash)).resolves.not.toThrow(); + return expect(testProvider.getBlock(exampleBlockHash)).resolves.not.toThrow(); }); test('getBlock(blockHash=undefined, blockNumber=null)', async () => { @@ -47,49 +60,49 @@ describe('defaultProvider', () => { }); test('getBlock() -> { blockNumber }', async () => { - const block = await provider.getBlock(); + const block = await testProvider.getBlock(); return expect(block).toHaveProperty('block_number'); }); describe('getStorageAt', () => { test('with "key" type of number', () => { return expect( - provider.getStorageAt(exampleContractAddress, 0, 36663) + testProvider.getStorageAt(exampleContractAddress, 0, 36663) ).resolves.not.toThrow(); }); test('"key" type of string', () => { return expect( - provider.getStorageAt(exampleContractAddress, '0x0', 36663) + testProvider.getStorageAt(exampleContractAddress, '0x0', 36663) ).resolves.not.toThrow(); }); test('with "key" type of BN', () => { return expect( - provider.getStorageAt(exampleContractAddress, toBN('0x0'), 36663) + testProvider.getStorageAt(exampleContractAddress, toBN('0x0'), 36663) ).resolves.not.toThrow(); }); test('(blockHash=undefined, blockNumber=null)', () => { - return expect(provider.getStorageAt(exampleContractAddress, 0)).resolves.not.toThrow(); + return expect(testProvider.getStorageAt(exampleContractAddress, 0)).resolves.not.toThrow(); }); }); test('getTransaction() - successful transaction', async () => { - const transaction = await provider.getTransaction(exampleTransactionHash); + const transaction = await testProvider.getTransaction(exampleTransactionHash); expect(transaction).toHaveProperty('transaction_hash'); }); test('getTransactionReceipt() - successful transaction', async () => { - const transactionReceipt = await provider.getTransactionReceipt(exampleTransactionHash); + const transactionReceipt = await testProvider.getTransactionReceipt(exampleTransactionHash); return expect(transactionReceipt).toHaveProperty('actual_fee'); }); test('callContract()', () => { return expect( - provider.callContract({ + testProvider.callContract({ contractAddress: exampleContractAddress, entrypoint: 'balance_of', calldata: compileCalldata({ @@ -100,7 +113,7 @@ describe('defaultProvider', () => { }); test('callContract() - gateway error', async () => { - const promise = provider.callContract({ + const promise = testProvider.callContract({ contractAddress: exampleContractAddress, entrypoint: 'non_existent_entrypoint', calldata: compileCalldata({ @@ -124,7 +137,7 @@ describe('defaultProvider', () => { describe('addTransaction()', () => { test('declareContract()', async () => { - const response = await provider.declareContract({ + const response = await testProvider.declareContract({ contract: compiledErc20, }); @@ -133,7 +146,7 @@ describe('defaultProvider', () => { }); test('deployContract()', async () => { - const response = await provider.deployContract({ + const response = await testProvider.deployContract({ contract: compiledOpenZeppelinAccount, }); @@ -141,4 +154,189 @@ describe('defaultProvider', () => { expect(response.contract_address).toBeDefined(); }); }); + + describe.each([ + { name: 'RPC', provider: getTestRpcProvider() }, + { name: 'Sequencer', provider: new SequencerProvider() }, + ])('$name provider', ({ name, provider }) => { + describe(`Provider methods: ${name}`, () => { + describe('getBlock', () => { + test('pending', async () => { + const latestBlock = await provider.getBlock(); + expect(latestBlock).toHaveProperty('block_hash'); + expect(latestBlock).toHaveProperty('parent_hash'); + expect(latestBlock).toHaveProperty('block_number'); + expect(latestBlock).toHaveProperty('status'); + expect(latestBlock).toHaveProperty('sequencer'); + expect(latestBlock).toHaveProperty('new_root'); + expect(latestBlock).toHaveProperty('old_root'); + expect(latestBlock).toHaveProperty('accepted_time'); + expect(latestBlock).toHaveProperty('gas_price'); + expect(latestBlock).toHaveProperty('transactions'); + expect(Array.isArray(latestBlock.transactions)).toBe(true); + }); + + test('Block Hash 0x8a30a1212d142cb0053fe9921e1dbf64f651d328565bd2e7ac24059c270f43', async () => { + const block = await provider.getBlock( + '0x8a30a1212d142cb0053fe9921e1dbf64f651d328565bd2e7ac24059c270f43' + ); + + expect(block).toHaveProperty('block_hash'); + expect(block).toHaveProperty('parent_hash'); + expect(block).toHaveProperty('block_number'); + expect(block).toHaveProperty('status'); + expect(block).toHaveProperty('sequencer'); + expect(block).toHaveProperty('new_root'); + expect(block).toHaveProperty('old_root'); + expect(block).toHaveProperty('accepted_time'); + expect(block).toHaveProperty('gas_price'); + expect(block).toHaveProperty('transactions'); + expect(Array.isArray(block.transactions)).toBe(true); + }); + + test('Block Number 102634', async () => { + const block = await provider.getBlock(102634); + expect(block).toHaveProperty('block_hash'); + expect(block).toHaveProperty('parent_hash'); + expect(block).toHaveProperty('block_number'); + expect(block).toHaveProperty('status'); + expect(block).toHaveProperty('sequencer'); + expect(block).toHaveProperty('new_root'); + expect(block).toHaveProperty('old_root'); + expect(block).toHaveProperty('accepted_time'); + expect(block).toHaveProperty('gas_price'); + expect(block).toHaveProperty('transactions'); + expect(Array.isArray(block.transactions)).toBe(true); + }); + }); + + describe('getStorageAt', () => { + test('pending', async () => { + const storage = await provider.getStorageAt( + '0x01d1f307c073bb786a66e6e042ec2a9bdc385a3373bb3738d95b966d5ce56166', + 0 + ); + expect(typeof storage).toBe('string'); + }); + + test('Block Hash 0x7104702055c2a5773a870ceada9552ec659d69c18053b14078983f07527dea8', async () => { + const storage = await provider.getStorageAt( + '0x01d1f307c073bb786a66e6e042ec2a9bdc385a3373bb3738d95b966d5ce56166', + 0, + '0x7225762c7ff5e7e5f0867f0a8e73594df4f44f05a65375339a76398e8ae3e64' + ); + expect(typeof storage).toBe('string'); + }); + }); + + describe('getTransaction', () => { + test('Deploy Transaction Hash 0x37013e1cb9c133e6fe51b4b371b76b317a480f56d80576730754c1662582348', async () => { + const transaction = await provider.getTransaction( + '0x37013e1cb9c133e6fe51b4b371b76b317a480f56d80576730754c1662582348' + ); + + expect(transaction.transaction_hash).toBeTruthy(); + expect(transaction.contract_address).toBeTruthy(); + }); + + test('Invoke Transaction Hash 0x2a56c636f45761c99a67ecdf0f185a6d5fe5239924ed9a4886fddbfaf3227b', async () => { + const transaction = await provider.getTransaction( + '0x2a56c636f45761c99a67ecdf0f185a6d5fe5239924ed9a4886fddbfaf3227b' + ); + + expect(transaction.transaction_hash).toBeTruthy(); + expect(transaction.contract_address).toBeTruthy(); + expect(Array.isArray(transaction.calldata)).toBe(true); + expect(transaction.entry_point_selector).toBeTruthy(); + expect(Array.isArray(transaction.signature)).toBe(true); + expect(transaction.max_fee).toBeTruthy(); + }); + + test('Declare Transaction Hash 0x79b130f2e808db6ab4b83f0182f016a128d73752b849e5b0221c2b3a35a87ea', async () => { + const transaction = await provider.getTransaction( + '0x79b130f2e808db6ab4b83f0182f016a128d73752b849e5b0221c2b3a35a87ea' + ); + + expect(transaction.max_fee).toBeTruthy(); + expect(transaction.transaction_hash).toBeTruthy(); + expect(transaction).toHaveProperty('nonce'); + expect(transaction).toHaveProperty('sender_address'); + expect(transaction).toHaveProperty('version'); + }); + }); + + describe('getTransactionReceipt', () => { + test('Transaction Hash 0x37013e1cb9c133e6fe51b4b371b76b317a480f56d80576730754c1662582348', async () => { + const receipt = await provider.getTransactionReceipt( + '0x37013e1cb9c133e6fe51b4b371b76b317a480f56d80576730754c1662582348' + ); + + expect(receipt).toHaveProperty('transaction_hash'); + expect(receipt).toHaveProperty('status'); + expect(receipt).toHaveProperty('status_data'); + expect(receipt).toHaveProperty('messages_sent'); + expect(receipt).toHaveProperty('l1_origin_message'); + expect(receipt).toHaveProperty('events'); + }); + }); + + describe('Contract methods', () => { + let contractAddress: string; + let deployResponse: DeployContractResponse; + let declareResponse: DeclareContractResponse; + + beforeAll(async () => { + deployResponse = await provider.deployContract({ contract: compiledErc20 }); + contractAddress = deployResponse.contract_address; + declareResponse = await provider.declareContract({ contract: compiledErc20 }); + await Promise.all([ + provider.waitForTransaction(deployResponse.transaction_hash), + provider.waitForTransaction(declareResponse.transaction_hash), + ]); + }); + + describe('deployContract', () => { + test('response', () => { + expect(deployResponse.contract_address).toBeTruthy(); + expect(deployResponse.transaction_hash).toBeTruthy(); + }); + }); + + describe('declareContract', () => { + test('response', async () => { + expect(declareResponse.class_hash).toBeTruthy(); + expect(declareResponse.transaction_hash).toBeTruthy(); + }); + }); + + describe('getClassAt', () => { + test('response', async () => { + // Hardcoded contract address as RPC node is throwing "Contract not found" error + const classResponse = await provider.getClassAt(contractAddress); + + expect(classResponse).toHaveProperty('program'); + expect(classResponse).toHaveProperty('entry_points_by_type'); + }); + }); + + describe('callContract', () => { + test('result', () => { + return expect( + provider + .callContract({ + contractAddress: deployResponse.contract_address, + entrypoint: 'balance_of', + calldata: compileCalldata({ + user: '0x9ff64f4ab0e1fe88df4465ade98d1ea99d5732761c39279b8e1374fa943e9b', + }), + }) + .then((res) => { + expect(Array.isArray(res.result)).toBe(true); + }) + ).resolves.not.toThrow(); + }); + }); + }); + }); + }); }); diff --git a/__tests__/fixtures.ts b/__tests__/fixtures.ts index 19c35db64..d6ac5618b 100644 --- a/__tests__/fixtures.ts +++ b/__tests__/fixtures.ts @@ -1,6 +1,6 @@ import fs from 'fs'; -import { Account, Provider, ec, json } from '../src'; +import { Account, Provider, RpcProvider, ec, json } from '../src'; import { CompiledContract } from '../src/types'; const readContract = (name: string): CompiledContract => @@ -55,6 +55,16 @@ export const getTestAccount = (provider = getTestProvider(), isDevnet = false) = return new Account(provider, testAccountAddress, ec.getKeyPair(testAccountPrivateKey)); }; +export const getTestRpcProvider = () => { + const { TEST_RPC_URL } = process.env; + + if (!TEST_RPC_URL) { + throw new Error('TEST_RPC_URL is not set'); + } + + return new RpcProvider({ nodeUrl: TEST_RPC_URL }); +}; + export const testIf = (condition: boolean) => (condition ? test : test.skip); export const describeIf = (condition: boolean) => (condition ? describe : describe.skip); export const testIfDevnet = testIf(IS_DEVNET); diff --git a/__tests__/rpcProvider.test.ts b/__tests__/rpcProvider.test.ts index bfbab81ce..3a825b35e 100644 --- a/__tests__/rpcProvider.test.ts +++ b/__tests__/rpcProvider.test.ts @@ -1,191 +1,14 @@ import { isBN } from 'bn.js'; -import { Account, Contract, DeployContractResponse, Provider, RPCProvider } from '../src'; +import { Account, Contract, Provider, RpcProvider } from '../src'; import { toBN } from '../src/utils/number'; -import { compileCalldata } from '../src/utils/stark'; -import { compiledErc20, describeIfNotDevnet, getTestAccount } from './fixtures'; - -const { TEST_RPC_URL } = process.env; - -if (!TEST_RPC_URL) { - throw new Error('TEST_RPC_URL is not set'); -} +import { compiledErc20, describeIfNotDevnet, getTestAccount, getTestRpcProvider } from './fixtures'; describe('RPCProvider', () => { - let provider: RPCProvider; + let provider: RpcProvider; beforeAll(async () => { - provider = new RPCProvider({ nodeUrl: TEST_RPC_URL }); - }); - - describe('Provider methods', () => { - describe('getBlock', () => { - test('pending', async () => { - const latestBlock = await provider.getBlock(); - expect(latestBlock).toHaveProperty('block_hash'); - expect(latestBlock).toHaveProperty('parent_hash'); - expect(latestBlock).toHaveProperty('block_number'); - expect(latestBlock).toHaveProperty('status'); - expect(latestBlock).toHaveProperty('sequencer'); - expect(latestBlock).toHaveProperty('new_root'); - expect(latestBlock).toHaveProperty('old_root'); - expect(latestBlock).toHaveProperty('accepted_time'); - expect(latestBlock).toHaveProperty('gas_price'); - expect(latestBlock).toHaveProperty('transactions'); - expect(Array.isArray(latestBlock.transactions)).toBe(true); - }); - - test('Block Hash 0x8a30a1212d142cb0053fe9921e1dbf64f651d328565bd2e7ac24059c270f43', async () => { - const block = await provider.getBlock( - '0x8a30a1212d142cb0053fe9921e1dbf64f651d328565bd2e7ac24059c270f43' - ); - - expect(block).toHaveProperty('block_hash'); - expect(block).toHaveProperty('parent_hash'); - expect(block).toHaveProperty('block_number'); - expect(block).toHaveProperty('status'); - expect(block).toHaveProperty('sequencer'); - expect(block).toHaveProperty('new_root'); - expect(block).toHaveProperty('old_root'); - expect(block).toHaveProperty('accepted_time'); - expect(block).toHaveProperty('gas_price'); - expect(block).toHaveProperty('transactions'); - expect(Array.isArray(block.transactions)).toBe(true); - }); - - test('Block Number 102634', async () => { - const block = await provider.getBlock(102634); - expect(block).toHaveProperty('block_hash'); - expect(block).toHaveProperty('parent_hash'); - expect(block).toHaveProperty('block_number'); - expect(block).toHaveProperty('status'); - expect(block).toHaveProperty('sequencer'); - expect(block).toHaveProperty('new_root'); - expect(block).toHaveProperty('old_root'); - expect(block).toHaveProperty('accepted_time'); - expect(block).toHaveProperty('gas_price'); - expect(block).toHaveProperty('transactions'); - expect(Array.isArray(block.transactions)).toBe(true); - }); - }); - - describe('getStorageAt', () => { - test('pending', async () => { - const storage = await provider.getStorageAt( - '0x01d1f307c073bb786a66e6e042ec2a9bdc385a3373bb3738d95b966d5ce56166', - 0 - ); - expect(typeof storage).toBe('string'); - }); - - test('Block Hash 0x7104702055c2a5773a870ceada9552ec659d69c18053b14078983f07527dea8', async () => { - const storage = await provider.getStorageAt( - '0x01d1f307c073bb786a66e6e042ec2a9bdc385a3373bb3738d95b966d5ce56166', - 0, - '0x7225762c7ff5e7e5f0867f0a8e73594df4f44f05a65375339a76398e8ae3e64' - ); - expect(typeof storage).toBe('string'); - }); - }); - - describe('getTransaction', () => { - test('Deploy Transaction Hash 0x37013e1cb9c133e6fe51b4b371b76b317a480f56d80576730754c1662582348', async () => { - const transaction = await provider.getTransaction( - '0x37013e1cb9c133e6fe51b4b371b76b317a480f56d80576730754c1662582348' - ); - - expect(transaction.transaction_hash).toBeTruthy(); - expect(transaction.contract_address).toBeTruthy(); - }); - - test('Invoke Transaction Hash 0x2a56c636f45761c99a67ecdf0f185a6d5fe5239924ed9a4886fddbfaf3227b', async () => { - const transaction = await provider.getTransaction( - '0x2a56c636f45761c99a67ecdf0f185a6d5fe5239924ed9a4886fddbfaf3227b' - ); - - expect(transaction.transaction_hash).toBeTruthy(); - expect(transaction.contract_address).toBeTruthy(); - expect(Array.isArray(transaction.calldata)).toBe(true); - expect(transaction.entry_point_selector).toBeTruthy(); - expect(Array.isArray(transaction.signature)).toBe(true); - expect(transaction.max_fee).toBeTruthy(); - }); - - test('Declare Transaction Hash 0x79b130f2e808db6ab4b83f0182f016a128d73752b849e5b0221c2b3a35a87ea', async () => { - const transaction = await provider.getTransaction( - '0x79b130f2e808db6ab4b83f0182f016a128d73752b849e5b0221c2b3a35a87ea' - ); - - expect(transaction.max_fee).toBeTruthy(); - expect(transaction.transaction_hash).toBeTruthy(); - }); - }); - - describe('getTransactionReceipt', () => { - test('Transaction Hash 0x37013e1cb9c133e6fe51b4b371b76b317a480f56d80576730754c1662582348', async () => { - const receipt = await provider.getTransactionReceipt( - '0x37013e1cb9c133e6fe51b4b371b76b317a480f56d80576730754c1662582348' - ); - - expect(receipt).toHaveProperty('transaction_hash'); - expect(receipt).toHaveProperty('status'); - expect(receipt).toHaveProperty('status_data'); - expect(receipt).toHaveProperty('messages_sent'); - expect(receipt).toHaveProperty('l1_origin_message'); - expect(receipt).toHaveProperty('events'); - }); - }); - }); - - describe('Contract methods', () => { - let contractAddress: string; - let deployTransactionHash: string; - let deployResponse: DeployContractResponse; - - beforeAll(async () => { - deployResponse = await provider.deployContract({ contract: compiledErc20 }); - contractAddress = deployResponse.contract_address; - deployTransactionHash = deployResponse.transaction_hash; - - await provider.waitForTransaction(deployTransactionHash); - }); - - test('Deployed contract', () => { - expect(deployResponse).toBeTruthy(); - expect(contractAddress).toBeTruthy(); - expect(deployTransactionHash).toBeTruthy(); - }); - - test('Declared contract', async () => { - const declareContractResponse = await provider.declareContract({ contract: compiledErc20 }); - - expect(declareContractResponse.class_hash).toBeTruthy(); - expect(declareContractResponse.transaction_hash).toBeTruthy(); - }); - - test('getClassAt', async () => { - const classResponse = await provider.getClassAt(contractAddress); - expect(classResponse).toHaveProperty('program'); - expect(classResponse).toHaveProperty('entry_points_by_type'); - }); - - describe('callContract', () => { - test('result', () => { - return expect( - provider - .callContract({ - contractAddress, - entrypoint: 'balance_of', - calldata: compileCalldata({ - user: '0x9ff64f4ab0e1fe88df4465ade98d1ea99d5732761c39279b8e1374fa943e9b', - }), - }) - .then((res) => { - expect(Array.isArray(res.result)).toBe(true); - }) - ).resolves.not.toThrow(); - }); - }); + provider = getTestRpcProvider(); }); describe('RPC methods', () => { @@ -201,7 +24,7 @@ describe('RPCProvider', () => { let erc20: Contract; beforeAll(async () => { - const rpcProvider = new Provider({ rpc: { nodeUrl: TEST_RPC_URL } }); + const rpcProvider = new Provider({ rpc: { nodeUrl: provider.nodeUrl } }); account = getTestAccount(rpcProvider, false); expect(account).toBeInstanceOf(Account); diff --git a/__tests__/sequencerProvider.test.ts b/__tests__/sequencerProvider.test.ts index 0e89e0350..fce1df34d 100644 --- a/__tests__/sequencerProvider.test.ts +++ b/__tests__/sequencerProvider.test.ts @@ -1,6 +1,4 @@ -import { DeclareContractResponse, DeployContractResponse, SequencerProvider } from '../src'; -import { compileCalldata } from '../src/utils/stark'; -import { compiledErc20 } from './fixtures'; +import { SequencerProvider } from '../src'; describe('SequencerProvider', () => { let provider: SequencerProvider; @@ -9,185 +7,6 @@ describe('SequencerProvider', () => { provider = new SequencerProvider(); }); - describe('Provider methods', () => { - describe('getBlock', () => { - test('pending', async () => { - const latestBlock = await provider.getBlock(); - expect(latestBlock).toHaveProperty('block_hash'); - expect(latestBlock).toHaveProperty('parent_hash'); - expect(latestBlock).toHaveProperty('block_number'); - expect(latestBlock).toHaveProperty('status'); - expect(latestBlock).toHaveProperty('sequencer'); - expect(latestBlock).toHaveProperty('new_root'); - expect(latestBlock).toHaveProperty('old_root'); - expect(latestBlock).toHaveProperty('accepted_time'); - expect(latestBlock).toHaveProperty('gas_price'); - expect(latestBlock).toHaveProperty('transactions'); - expect(Array.isArray(latestBlock.transactions)).toBe(true); - }); - - test('Block Hash 0x8a30a1212d142cb0053fe9921e1dbf64f651d328565bd2e7ac24059c270f43', async () => { - const block = await provider.getBlock( - '0x8a30a1212d142cb0053fe9921e1dbf64f651d328565bd2e7ac24059c270f43' - ); - - expect(block).toHaveProperty('block_hash'); - expect(block).toHaveProperty('parent_hash'); - expect(block).toHaveProperty('block_number'); - expect(block).toHaveProperty('status'); - expect(block).toHaveProperty('sequencer'); - expect(block).toHaveProperty('new_root'); - expect(block).toHaveProperty('old_root'); - expect(block).toHaveProperty('accepted_time'); - expect(block).toHaveProperty('gas_price'); - expect(block).toHaveProperty('transactions'); - expect(Array.isArray(block.transactions)).toBe(true); - }); - - test('Block Number 102634', async () => { - const block = await provider.getBlock(102634); - expect(block).toHaveProperty('block_hash'); - expect(block).toHaveProperty('parent_hash'); - expect(block).toHaveProperty('block_number'); - expect(block).toHaveProperty('status'); - expect(block).toHaveProperty('sequencer'); - expect(block).toHaveProperty('new_root'); - expect(block).toHaveProperty('old_root'); - expect(block).toHaveProperty('accepted_time'); - expect(block).toHaveProperty('gas_price'); - expect(block).toHaveProperty('transactions'); - expect(Array.isArray(block.transactions)).toBe(true); - }); - }); - - describe('getStorageAt', () => { - test('pending', async () => { - const storage = await provider.getStorageAt( - '0x01d1f307c073bb786a66e6e042ec2a9bdc385a3373bb3738d95b966d5ce56166', - 0 - ); - expect(typeof storage).toBe('string'); - }); - - test('Block Hash 0x7104702055c2a5773a870ceada9552ec659d69c18053b14078983f07527dea8', async () => { - const storage = await provider.getStorageAt( - '0x01d1f307c073bb786a66e6e042ec2a9bdc385a3373bb3738d95b966d5ce56166', - 0, - '0x7225762c7ff5e7e5f0867f0a8e73594df4f44f05a65375339a76398e8ae3e64' - ); - expect(typeof storage).toBe('string'); - }); - }); - - describe('getTransaction', () => { - test('Deploy Transaction Hash 0x37013e1cb9c133e6fe51b4b371b76b317a480f56d80576730754c1662582348', async () => { - const transaction = await provider.getTransaction( - '0x37013e1cb9c133e6fe51b4b371b76b317a480f56d80576730754c1662582348' - ); - - expect(transaction.transaction_hash).toBeTruthy(); - expect(transaction.contract_address).toBeTruthy(); - }); - - test('Invoke Transaction Hash 0x2a56c636f45761c99a67ecdf0f185a6d5fe5239924ed9a4886fddbfaf3227b', async () => { - const transaction = await provider.getTransaction( - '0x2a56c636f45761c99a67ecdf0f185a6d5fe5239924ed9a4886fddbfaf3227b' - ); - - expect(transaction.transaction_hash).toBeTruthy(); - expect(transaction.contract_address).toBeTruthy(); - expect(Array.isArray(transaction.calldata)).toBe(true); - expect(transaction.entry_point_selector).toBeTruthy(); - expect(Array.isArray(transaction.signature)).toBe(true); - expect(transaction.max_fee).toBeTruthy(); - }); - - test('Declare Transaction Hash 0x79b130f2e808db6ab4b83f0182f016a128d73752b849e5b0221c2b3a35a87ea', async () => { - const transaction = await provider.getTransaction( - '0x79b130f2e808db6ab4b83f0182f016a128d73752b849e5b0221c2b3a35a87ea' - ); - - expect(transaction.max_fee).toBeTruthy(); - expect(transaction.nonce).toBeTruthy(); - expect(transaction.sender_address).toBeTruthy(); - expect(transaction.transaction_hash).toBeTruthy(); - expect(transaction.version).toBeTruthy(); - }); - }); - - describe('getTransactionReceipt', () => { - test('Transaction Hash 0x37013e1cb9c133e6fe51b4b371b76b317a480f56d80576730754c1662582348', async () => { - const receipt = await provider.getTransactionReceipt( - '0x37013e1cb9c133e6fe51b4b371b76b317a480f56d80576730754c1662582348' - ); - - expect(receipt).toHaveProperty('transaction_hash'); - expect(receipt).toHaveProperty('status'); - expect(receipt).toHaveProperty('status_data'); - expect(receipt).toHaveProperty('messages_sent'); - expect(receipt).toHaveProperty('l1_origin_message'); - expect(receipt).toHaveProperty('events'); - }); - }); - - describe('Contract methods', () => { - let deployResponse: DeployContractResponse; - let declareResponse: DeclareContractResponse; - - beforeAll(async () => { - deployResponse = await provider.deployContract({ contract: compiledErc20 }); - declareResponse = await provider.declareContract({ contract: compiledErc20 }); - await Promise.all([ - provider.waitForTransaction(deployResponse.transaction_hash), - provider.waitForTransaction(declareResponse.transaction_hash), - ]); - }); - - describe('deployContract', () => { - test('response', () => { - expect(deployResponse.contract_address).toBeTruthy(); - expect(deployResponse.transaction_hash).toBeTruthy(); - }); - }); - - describe('declareContract', () => { - test('response', async () => { - expect(declareResponse.class_hash).toBeTruthy(); - expect(declareResponse.transaction_hash).toBeTruthy(); - }); - }); - - describe('getClassAt', () => { - test('response', async () => { - // Hardcoded contract address as RPC node is throwing "Contract not found" error - const classResponse = await provider.getClassAt( - '0x0377cd03f6bed2ed201e9783f50b1b823d2ff65032da69f468bba5c6634dfbfa' - ); - expect(classResponse).toHaveProperty('program'); - expect(classResponse).toHaveProperty('entry_points_by_type'); - }); - }); - - describe('callContract', () => { - test('result', () => { - return expect( - provider - .callContract({ - contractAddress: deployResponse.contract_address, - entrypoint: 'balance_of', - calldata: compileCalldata({ - user: '0x9ff64f4ab0e1fe88df4465ade98d1ea99d5732761c39279b8e1374fa943e9b', - }), - }) - .then((res) => { - expect(Array.isArray(res.result)).toBe(true); - }) - ).resolves.not.toThrow(); - }); - }); - }); - }); - describe('Gateway specifc methods', () => { const exampleTransactionHash = '0x37013e1cb9c133e6fe51b4b371b76b317a480f56d80576730754c1662582348';