Skip to content

Commit

Permalink
[VM] fix test
Browse files Browse the repository at this point in the history
fix test; update comment

lint

fix test

fix grammar

Co-authored-by: Ryan Ghods <ryan@ryanio.com>

fix spelling

Co-authored-by: Ryan Ghods <ryan@ryanio.com>
  • Loading branch information
jochem-brouwer and ryanio committed Sep 23, 2020
1 parent 156ada2 commit ae8f63c
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 16 deletions.
4 changes: 2 additions & 2 deletions packages/vm/lib/state/stateManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -276,7 +276,7 @@ export default class DefaultStateManager implements StateManager {
* corresponding to `address` at the provided `key`.
* @param address - Address to set a storage value for
* @param key - Key to set the value at. Must be 32 bytes long.
* @param value - Value to set at `key` for account corresponding to `address`. Cannot be more than 32 bytes. Will be left-padded with zeros if less than 32 bytes. If it is a empty or filled with zeros, delete the value.
* @param value - Value to set at `key` for account corresponding to `address`. Cannot be more than 32 bytes. Leading zeros are stripped. If it is a empty or filled with zeros, deletes the value.
*/
async putContractStorage(address: Buffer, key: Buffer, value: Buffer): Promise<void> {
if (key.length !== 32) {
Expand Down Expand Up @@ -421,7 +421,7 @@ export default class DefaultStateManager implements StateManager {
}

/**
* Dumps the the RLP-encoded storage values for an `account` specified by `address`.
* Dumps the RLP-encoded storage values for an `account` specified by `address`.
* @param address - The address of the `account` to return storage for
* @returns {Promise<StorageDump>} - The state of the account as an `Object` map.
* Keys are are the storage keys, values are the storage values as strings.
Expand Down
28 changes: 14 additions & 14 deletions packages/vm/tests/api/state/stateManager.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -413,29 +413,29 @@ tape('StateManager - Contract code', (tester) => {
tape('StateManager - Contract storage', (tester) => {
const it = tester.test

it('should throw on storage values larger than 32 bytes', async(t) => {
it('should throw on storage values larger than 32 bytes', async (t) => {
t.plan(1)
const stateManager = new DefaultStateManager()
const address = zeros(20)
const key = zeros(32)
const value = Buffer.from(("aa").repeat(33), 'hex')
const value = Buffer.from('aa'.repeat(33), 'hex')
try {
await stateManager.putContractStorage(address, key, value)
t.fail("did not throw")
t.fail('did not throw')
} catch (e) {
t.pass("threw on trying to set storage values larger than 32 bytes")
t.pass('threw on trying to set storage values larger than 32 bytes')
}
t.end()
})

it('should strip storage values lower than 32 bytes', async(t) => {
it('should strip storage values lower than 32 bytes', async (t) => {
const stateManager = new DefaultStateManager()
const address = zeros(20)
const key0 = zeros(32)
const value0 = Buffer.from(("aa").repeat(31), 'hex') // put a value of 31-bytes length
const value0 = Buffer.from('aa'.repeat(31), 'hex') // put a value of 31-bytes length
const expect0 = unpadBuffer(value0)
const key1 = Buffer.concat([zeros(31), Buffer.from('01', 'hex')])
const value1 = Buffer.from(("aa").repeat(1), 'hex') // put a vlaue of 1-byte length
const value1 = Buffer.from('aa'.repeat(1), 'hex') // put a vlaue of 1-byte length
const expect1 = unpadBuffer(value1)

await stateManager.putContractStorage(address, key0, value0)
Expand All @@ -448,12 +448,12 @@ tape('StateManager - Contract storage', (tester) => {
t.end()
})

it ('should delete storage values which only consist of zero bytes', async(t) => {
it('should delete storage values which only consist of zero bytes', async (t) => {
const address = zeros(20)
const key = zeros(32)
const startValue = Buffer.from('01', 'hex')

const zeroLengths = [0, 1, 31, 32] // checks for arbitrary-length zeros
const zeroLengths = [0, 1, 31, 32] // checks for arbitrary-length zeros
t.plan(zeroLengths.length)

for (let length of zeroLengths) {
Expand All @@ -463,18 +463,18 @@ tape('StateManager - Contract storage', (tester) => {
const currentValue = await stateManager.getContractStorage(address, key)
if (!currentValue.equals(startValue)) {
// sanity check
t.fail("contract value not set correctly")
t.fail('contract value not set correctly')
} else {
// delete the value
// delete the value
await stateManager.putContractStorage(address, key, value)
const deleted = await stateManager.getContractStorage(address, key)
t.ok(deleted.equals(zeros(0)), "the storage key should be deleted")
t.ok(deleted.equals(zeros(0)), 'the storage key should be deleted')
}
}
t.end()
})

it('should not strip trailing zeros', async(t) => {
it('should not strip trailing zeros', async (t) => {
const address = zeros(20)
const key = zeros(32)
const value = Buffer.from('0000aabb00', 'hex')
Expand All @@ -485,4 +485,4 @@ tape('StateManager - Contract storage', (tester) => {
t.ok(contractValue.equals(expect), 'trailing zeros are not stripped')
t.end()
})
})
})

1 comment on commit ae8f63c

@github-actions
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Benchmark

Benchmark suite Current: ae8f63c Previous: d62d9f2 Ratio
Block 9422905 1766 ops/sec (±3.00%) 1772 ops/sec (±2.57%) 1.00
Block 9422906 1743 ops/sec (±6.10%) 1655 ops/sec (±7.86%) 0.95
Block 9422907 1790 ops/sec (±1.04%) 1719 ops/sec (±1.15%) 0.96
Block 9422908 1731 ops/sec (±1.04%) 1676 ops/sec (±1.53%) 0.97
Block 9422909 1700 ops/sec (±1.36%) 1658 ops/sec (±1.42%) 0.98
Block 9422910 1700 ops/sec (±1.28%) 1612 ops/sec (±1.78%) 0.95
Block 9422911 1354 ops/sec (±12.58%) 1577 ops/sec (±1.92%) 1.16
Block 9422912 1649 ops/sec (±1.00%) 1578 ops/sec (±1.96%) 0.96
Block 9422913 1595 ops/sec (±1.72%) 1103 ops/sec (±18.51%) 0.69
Block 9422914 1551 ops/sec (±1.71%) 1555 ops/sec (±1.63%) 1.00

This comment was automatically generated by workflow using github-action-benchmark.

Please sign in to comment.