Skip to content

Commit

Permalink
Merge pull request #45 from vechain/andrew/add-tests_283
Browse files Browse the repository at this point in the history
Andrew/add tests 283
  • Loading branch information
darrenvechain authored Oct 24, 2024
2 parents 605d8eb + 4eefd84 commit 8efb77f
Showing 1 changed file with 68 additions and 0 deletions.
68 changes: 68 additions & 0 deletions test/thorest-api/debug/storage-range.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@

import { Client, Schema } from '../../../src/thor-client'
import { contractAddresses } from '../../../src/contracts/addresses'
import { interfaces } from '../../../src/contracts/hardhat'
import { HEX_AT_LEAST_1, HEX_REGEX_40 } from '../../../src/utils/hex-utils'
import {
SimpleCounter__factory as SimpleCounter,
} from '../../../typechain-types'
import { revisions } from '../../../src/constants'
import {
addAddressPadding,
addUintPadding,
} from '../../../src/utils/padding-utils'
import { ThorWallet } from '../../../src/wallet'
import { components } from '../../../src/open-api-types'
import { Contract } from '@vechain/sdk-network'
import { pollReceipt } from '../../../src/transactions'

const SEND_VTHO_AMOUNT = '0x1'
const SEND_VTHO_CLAUSE = {
to: contractAddresses.energy,
value: '0x0',
data: interfaces.energy.encodeFunctionData('transfer', [
ThorWallet.withFunds().address,
SEND_VTHO_AMOUNT,
]),
}

describe('GET /debug/storage-range', () => {
const sender = ThorWallet.withFunds()
let transaction_first: components['schemas']['GetTxReceiptResponse']
let transaction: components['schemas']['GetTxReceiptResponse']
let counter: Contract<typeof SimpleCounter.abi>
beforeAll(async () => {
counter = await sender.deployContract(
SimpleCounter.bytecode,
SimpleCounter.abi,
)

let incrementTx = await counter.transact.incrementCounter()
transaction_first = await pollReceipt(incrementTx.id)

incrementTx = await counter.transact.incrementCounter()
transaction = await pollReceipt(incrementTx.id)

incrementTx = await counter.transact.incrementCounter()
await pollReceipt(incrementTx.id)
})


it.e2eTest('should get non empty storage, empty maxResult', 'all', async () => {
let storage = await Client.sdk.debug.retrieveStorageRange({ target: { blockID: transaction?.meta?.blockID!, transaction: 0, clauseIndex: 0 }, options: { address: counter.address, maxResult: 10 } })
expect(Object.keys(storage.storage).length).toBeGreaterThan(0)
expect(storage.nextKey).toBeNull()
})

it.e2eTest('should get non empty storage, provided maxResult', 'all', async () => {
let storage = await Client.sdk.debug.retrieveStorageRange({ target: { blockID: transaction?.meta?.blockID!, transaction: transaction?.meta?.txID!, clauseIndex: 0 }, options: { address: counter.address, maxResult: 1 } })
expect(Object.keys(storage.storage).length).toBe(1)
expect(storage.nextKey).toBeNull()
})

it.e2eTest('get storage must fail, too large maxResult', 'all', async () => {
let response = await Client.raw.retrieveStorageRange({ target: `${transaction?.meta?.blockID!}/${transaction?.meta?.txID!}/0`, maxResult: 10000000000 })
expect(response.success).toBeFalse()
expect(response.httpCode).toBe(400)
})
})

0 comments on commit 8efb77f

Please sign in to comment.