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 Oct 1, 2020
1 parent 0fa3ff6 commit 21e43e6
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 21e43e6

@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: 21e43e6 Previous: 0103b50 Ratio
Block 9422905 1609 ops/sec (±2.13%) 1712 ops/sec (±2.80%) 1.06
Block 9422906 1595 ops/sec (±4.68%) 1638 ops/sec (±8.56%) 1.03
Block 9422907 1631 ops/sec (±0.87%) 1746 ops/sec (±1.71%) 1.07
Block 9422908 1629 ops/sec (±0.75%) 1717 ops/sec (±1.00%) 1.05
Block 9422909 1615 ops/sec (±0.52%) 1674 ops/sec (±1.30%) 1.04
Block 9422910 1363 ops/sec (±9.88%) 1393 ops/sec (±11.11%) 1.02
Block 9422911 1565 ops/sec (±0.83%) 1564 ops/sec (±1.91%) 1.00
Block 9422912 1552 ops/sec (±0.89%) 1567 ops/sec (±1.46%) 1.01
Block 9422913 1529 ops/sec (±0.75%) 1600 ops/sec (±1.83%) 1.05
Block 9422914 1527 ops/sec (±0.61%) 1600 ops/sec (±1.49%) 1.05

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

Please sign in to comment.