@Test public void shouldGetHashOfAccountCodeWhenCodeIsPresent() { final BytesValue code = BytesValue.fromHexString("0xabcdef"); worldStateUpdater.getOrCreate(REQUESTED_ADDRESS).setCode(code); assertThat(executeOperation(REQUESTED_ADDRESS)).isEqualTo(Hash.hash(code)); }
public static void insertAccount( final WorldUpdater updater, final Address address, final AccountMock toCopy) { final MutableAccount account = updater.getOrCreate(address); account.setNonce(toCopy.nonce()); account.setBalance(toCopy.balance()); account.setCode(toCopy.code()); for (final Map.Entry<UInt256, UInt256> entry : toCopy.storage().entrySet()) { account.setStorageValue(entry.getKey(), entry.getValue()); } }
@Test public void shouldZeroOutLeftMostBitsToGetAddress() { // If EXTCODEHASH of A is X, then EXTCODEHASH of A + 2**160 is X. final BytesValue code = BytesValue.fromHexString("0xabcdef"); worldStateUpdater.getOrCreate(REQUESTED_ADDRESS).setCode(code); final Bytes32 value = Words.fromAddress(REQUESTED_ADDRESS) .asUInt256() .plus(UInt256.of(2).pow(UInt256.of(160))) .getBytes(); final MessageFrame frame = createMessageFrame(value); operation.execute(frame); assertThat(frame.getStackItem(0)).isEqualTo(Hash.hash(code)); }
@Test public void replaceAccountCode() { final MutableWorldState worldState = createEmpty(); final WorldUpdater updater = worldState.updater(); final MutableAccount account = updater.createAccount(ADDRESS); account.setBalance(Wei.of(100000)); account.setCode(BytesValue.of(1, 2, 3)); account.setCode(BytesValue.of(3, 2, 1)); updater.commit(); assertEquals(BytesValue.of(3, 2, 1), worldState.get(ADDRESS).getCode()); assertEquals( Hash.fromHexString("0xc14f5e30581de9155ea092affa665fad83bcd9f98e45c4a42885b9b36d939702"), worldState.rootHash()); }