forked from hyperledger/besu
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix account copy issue (hyperledger#6845)
Signed-off-by: Karim Taam <[email protected]>
- Loading branch information
Showing
3 changed files
with
121 additions
and
21 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
74 changes: 74 additions & 0 deletions
74
.../src/test/java/org/hyperledger/besu/ethereum/trie/diffbased/bonsai/BonsaiAccountTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
/* | ||
* Copyright Hyperledger Besu Contributors. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with | ||
* the License. You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on | ||
* an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the | ||
* specific language governing permissions and limitations under the License. | ||
* | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
package org.hyperledger.besu.ethereum.trie.diffbased.bonsai; | ||
|
||
import static org.assertj.core.api.Assertions.assertThat; | ||
|
||
import org.hyperledger.besu.datatypes.Address; | ||
import org.hyperledger.besu.datatypes.Hash; | ||
import org.hyperledger.besu.datatypes.Wei; | ||
import org.hyperledger.besu.ethereum.trie.diffbased.bonsai.worldview.BonsaiWorldState; | ||
import org.hyperledger.besu.evm.worldstate.UpdateTrackingAccount; | ||
|
||
import org.apache.tuweni.bytes.Bytes; | ||
import org.apache.tuweni.units.bigints.UInt256; | ||
import org.junit.jupiter.api.Test; | ||
import org.mockito.Mock; | ||
|
||
public class BonsaiAccountTest { | ||
|
||
@Mock BonsaiWorldState bonsaiWorldState; | ||
|
||
@Test | ||
void shouldCopyTrackedBonsaiAccountCorrectly() { | ||
final BonsaiAccount trackedAccount = | ||
new BonsaiAccount( | ||
bonsaiWorldState, | ||
Address.ZERO, | ||
Hash.hash(Address.ZERO), | ||
0, | ||
Wei.ONE, | ||
Hash.EMPTY_TRIE_HASH, | ||
Hash.EMPTY, | ||
true); | ||
trackedAccount.setCode(Bytes.of(1)); | ||
final UpdateTrackingAccount<BonsaiAccount> bonsaiAccountUpdateTrackingAccount = | ||
new UpdateTrackingAccount<>(trackedAccount); | ||
bonsaiAccountUpdateTrackingAccount.setStorageValue(UInt256.ONE, UInt256.ONE); | ||
|
||
final BonsaiAccount expectedAccount = new BonsaiAccount(trackedAccount, bonsaiWorldState, true); | ||
expectedAccount.setStorageValue(UInt256.ONE, UInt256.ONE); | ||
assertThat(new BonsaiAccount(bonsaiWorldState, bonsaiAccountUpdateTrackingAccount)) | ||
.isEqualToComparingFieldByField(expectedAccount); | ||
} | ||
|
||
@Test | ||
void shouldCopyBonsaiAccountCorrectly() { | ||
final BonsaiAccount account = | ||
new BonsaiAccount( | ||
bonsaiWorldState, | ||
Address.ZERO, | ||
Hash.hash(Address.ZERO), | ||
0, | ||
Wei.ONE, | ||
Hash.EMPTY_TRIE_HASH, | ||
Hash.EMPTY, | ||
true); | ||
account.setCode(Bytes.of(1)); | ||
account.setStorageValue(UInt256.ONE, UInt256.ONE); | ||
assertThat(new BonsaiAccount(account, bonsaiWorldState, true)) | ||
.isEqualToComparingFieldByField(account); | ||
} | ||
} |