Skip to content

Commit

Permalink
vm -> expand test, fix comment typos
Browse files Browse the repository at this point in the history
  • Loading branch information
jochem-brouwer committed Oct 1, 2020
1 parent 21e43e6 commit 5217f50
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 7 deletions.
2 changes: 1 addition & 1 deletion packages/vm/lib/state/stateManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -284,7 +284,7 @@ export default class DefaultStateManager implements StateManager {
}

if (value.length > 32) {
throw new Error('Storage key cannot be longer than 32 bytes')
throw new Error('Storage value cannot be longer than 32 bytes')
}

value = unpadBuffer(value)
Expand Down
13 changes: 7 additions & 6 deletions packages/vm/tests/api/state/stateManager.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -428,22 +428,23 @@ tape('StateManager - Contract storage', (tester) => {
t.end()
})

it('should strip storage values lower than 32 bytes', async (t) => {
it('should strip zeros of storage values', 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('00' + 'aa'.repeat(30), 'hex') // put a value of 31-bytes length with a leading zero byte
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 expect1 = unpadBuffer(value1)

await stateManager.putContractStorage(address, key0, value0)
const slot0 = await stateManager.getContractStorage(address, key0)
t.ok(slot0.equals(expect0), 'value of 31 bytes padded correctly')

const key1 = Buffer.concat([zeros(31), Buffer.from('01', 'hex')])
const value1 = Buffer.from('0000' + 'aa'.repeat(1), 'hex') // put a value of 1-byte length with two leading zero bytes
const expect1 = unpadBuffer(value1)
await stateManager.putContractStorage(address, key1, value1)
const slot1 = await stateManager.getContractStorage(address, key1)

t.ok(slot1.equals(expect1), 'value of 1 byte padded correctly')
t.end()
})
Expand Down

1 comment on commit 5217f50

@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: 5217f50 Previous: 0103b50 Ratio
Block 9422905 1772 ops/sec (±2.53%) 1712 ops/sec (±2.80%) 0.97
Block 9422906 1657 ops/sec (±6.73%) 1638 ops/sec (±8.56%) 0.99
Block 9422907 1730 ops/sec (±1.45%) 1746 ops/sec (±1.71%) 1.01
Block 9422908 1722 ops/sec (±1.14%) 1717 ops/sec (±1.00%) 1.00
Block 9422909 1706 ops/sec (±0.72%) 1674 ops/sec (±1.30%) 0.98
Block 9422910 1662 ops/sec (±1.69%) 1393 ops/sec (±11.11%) 0.84
Block 9422911 1638 ops/sec (±1.62%) 1564 ops/sec (±1.91%) 0.95
Block 9422912 1620 ops/sec (±2.12%) 1567 ops/sec (±1.46%) 0.97
Block 9422913 1227 ops/sec (±15.42%) 1600 ops/sec (±1.83%) 1.30
Block 9422914 1523 ops/sec (±5.71%) 1600 ops/sec (±1.49%) 1.05

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

Please sign in to comment.