diff --git a/aion_api b/aion_api index dce388bfb7..d376d56947 160000 --- a/aion_api +++ b/aion_api @@ -1 +1 @@ -Subproject commit dce388bfb792e6818e73da95f2a09147ba7dfd80 +Subproject commit d376d569476813cae6fea5fd3bfddc8654210301 diff --git a/aion_fastvm b/aion_fastvm index 4551db4a33..1ffdf35dcb 160000 --- a/aion_fastvm +++ b/aion_fastvm @@ -1 +1 @@ -Subproject commit 4551db4a33188dce7091ffe7e24ce5533532a8f4 +Subproject commit 1ffdf35dcb26e5d40d65e00013506f7461369b52 diff --git a/aion_vm_api b/aion_vm_api index e609864af9..f7a35da869 160000 --- a/aion_vm_api +++ b/aion_vm_api @@ -1 +1 @@ -Subproject commit e609864af94a5053a3a1d01a61d8ecfd7c131cb3 +Subproject commit f7a35da869f141fa65e7b768d2e4622237871f4a diff --git a/modAion/src/org/aion/zero/api/BlockConstants.java b/modAion/src/org/aion/zero/api/BlockConstants.java index e8bf3b0e06..1e9fd087c9 100644 --- a/modAion/src/org/aion/zero/api/BlockConstants.java +++ b/modAion/src/org/aion/zero/api/BlockConstants.java @@ -4,6 +4,7 @@ import org.aion.base.type.AionAddress; import org.aion.mcf.blockchain.IBlockConstants; import org.aion.mcf.types.AbstractBlockHeader; +import org.aion.vm.api.interfaces.Address; public class BlockConstants implements IBlockConstants { @@ -178,7 +179,7 @@ public long getClockDriftBufferTime() { * * @return {@code address} of the sk owning this pair. Also referred to as the owner's address. */ - public AionAddress getTokenBridgingAddress() { + public Address getTokenBridgingAddress() { return AionAddress.ZERO_ADDRESS(); } diff --git a/modAion/src/org/aion/zero/types/A0BlockHeader.java b/modAion/src/org/aion/zero/types/A0BlockHeader.java index 6a21112b83..6dc9da8b3e 100644 --- a/modAion/src/org/aion/zero/types/A0BlockHeader.java +++ b/modAion/src/org/aion/zero/types/A0BlockHeader.java @@ -16,6 +16,7 @@ import org.aion.mcf.types.AbstractBlockHeader; import org.aion.rlp.RLP; import org.aion.rlp.RLPList; +import org.aion.vm.api.interfaces.Address; import org.aion.zero.exceptions.HeaderStructureException; import org.json.JSONObject; @@ -205,7 +206,7 @@ public A0BlockHeader( byte version, long number, byte[] parentHash, - AionAddress coinbase, + Address coinbase, byte[] logsBloom, byte[] difficulty, byte[] extraData, @@ -215,7 +216,7 @@ public A0BlockHeader( byte[] nonce, byte[] solution) { this.version = version; - this.coinbase = coinbase; + this.coinbase = (AionAddress) coinbase; this.parentHash = parentHash; this.logsBloom = logsBloom; this.difficulty = difficulty; @@ -558,11 +559,11 @@ public static class Builder { * Some constants for fallbacks, these are not rigorously defined this; * TODO: define these with explanations in the future */ - protected AionAddress EMPTY_ADDRESS = AionAddress.EMPTY_ADDRESS(); + protected Address EMPTY_ADDRESS = AionAddress.EMPTY_ADDRESS(); protected byte version; protected byte[] parentHash; - protected AionAddress coinbase; + protected Address coinbase; protected byte[] stateRoot; protected byte[] txTrieRoot; protected byte[] receiptTrieRoot; @@ -620,7 +621,7 @@ public Builder withParentHash(byte[] parentHash) throws HeaderStructureException return this; } - public Builder withCoinbase(AionAddress coinbase) throws HeaderStructureException { + public Builder withCoinbase(Address coinbase) throws HeaderStructureException { if (isFromUnsafeSource) { if (coinbase == null) throw new HeaderStructureException( diff --git a/modAion/src/org/aion/zero/types/AionTransaction.java b/modAion/src/org/aion/zero/types/AionTransaction.java index 4121e5bc5e..bd327d7c95 100644 --- a/modAion/src/org/aion/zero/types/AionTransaction.java +++ b/modAion/src/org/aion/zero/types/AionTransaction.java @@ -265,7 +265,7 @@ public ISignature getSignature() { return signature; } - public AionAddress getContractAddress() { + public Address getContractAddress() { if (!this.isContractCreationTransaction()) { return null; } diff --git a/modAion/src/org/aion/zero/types/IAionBlock.java b/modAion/src/org/aion/zero/types/IAionBlock.java index ce1c86c0f7..cb462db278 100644 --- a/modAion/src/org/aion/zero/types/IAionBlock.java +++ b/modAion/src/org/aion/zero/types/IAionBlock.java @@ -2,13 +2,13 @@ import java.math.BigInteger; import java.util.List; -import org.aion.base.type.AionAddress; import org.aion.base.type.IBlock; +import org.aion.vm.api.interfaces.Address; /** aion block interface. */ public interface IAionBlock extends IBlock { - AionAddress getCoinbase(); + Address getCoinbase(); long getTimestamp(); diff --git a/modAion/test/org/aion/types/AionTransactionTest.java b/modAion/test/org/aion/types/AionTransactionTest.java index c4c32bdf50..aa1947e94f 100644 --- a/modAion/test/org/aion/types/AionTransactionTest.java +++ b/modAion/test/org/aion/types/AionTransactionTest.java @@ -6,6 +6,7 @@ import org.aion.base.type.AionAddress; import org.aion.crypto.ECKeyFac; import org.aion.mcf.vm.types.DataWord; +import org.aion.vm.api.interfaces.Address; import org.aion.zero.types.AionTransaction; import org.apache.commons.lang3.RandomUtils; import org.junit.Test; @@ -30,7 +31,7 @@ private void assertTransactionEquals(AionTransaction tx, AionTransaction tx2) { @Test public void testSerializationZero() { byte[] nonce = RandomUtils.nextBytes(16); - AionAddress to = AionAddress.wrap(RandomUtils.nextBytes(32)); + Address to = AionAddress.wrap(RandomUtils.nextBytes(32)); byte[] value = RandomUtils.nextBytes(16); byte[] data = RandomUtils.nextBytes(64); long nrg = 0; @@ -48,7 +49,7 @@ public void testSerializationZero() { @Test public void testClone() { byte[] nonce = RandomUtils.nextBytes(16); - AionAddress to = AionAddress.wrap(RandomUtils.nextBytes(32)); + Address to = AionAddress.wrap(RandomUtils.nextBytes(32)); byte[] value = RandomUtils.nextBytes(16); byte[] data = RandomUtils.nextBytes(64); long nrg = RandomUtils.nextLong(0, Long.MAX_VALUE); @@ -67,7 +68,7 @@ public void testClone() { public void testTransactionCost() { byte[] nonce = DataWord.ONE.getData(); byte[] from = RandomUtils.nextBytes(20); - byte[] to = RandomUtils.nextBytes(AionAddress.SIZE); + byte[] to = RandomUtils.nextBytes(Address.SIZE); byte[] value = DataWord.ONE.getData(); byte[] data = RandomUtils.nextBytes(128); long nrg = new DataWord(1000L).longValue(); @@ -86,8 +87,8 @@ public void testTransactionCost() { @Test public void testTransactionCost2() { byte[] nonce = DataWord.ONE.getData(); - byte[] from = RandomUtils.nextBytes(AionAddress.SIZE); - AionAddress to = AionAddress.EMPTY_ADDRESS(); + byte[] from = RandomUtils.nextBytes(Address.SIZE); + Address to = AionAddress.EMPTY_ADDRESS(); byte[] value = DataWord.ONE.getData(); byte[] data = RandomUtils.nextBytes(128); long nrg = new DataWord(1000L).longValue(); diff --git a/modAionBase/src/org/aion/base/type/IBlockHeader.java b/modAionBase/src/org/aion/base/type/IBlockHeader.java index df7ef4c1f4..7b7092737f 100644 --- a/modAionBase/src/org/aion/base/type/IBlockHeader.java +++ b/modAionBase/src/org/aion/base/type/IBlockHeader.java @@ -1,5 +1,7 @@ package org.aion.base.type; +import org.aion.vm.api.interfaces.Address; + /** @author jay */ public interface IBlockHeader { @@ -22,14 +24,14 @@ public interface IBlockHeader { byte[] getEncoded(); - AionAddress getCoinbase(); + Address getCoinbase(); long getTimestamp(); long getNumber(); // Setter - void setCoinbase(AionAddress _cb); + void setCoinbase(Address _cb); void setStateRoot(byte[] _strt); diff --git a/modAionBase/test/org/aion/base/type/AddressTest.java b/modAionBase/test/org/aion/base/type/AddressTest.java index dcdfdc3041..7e28a8f900 100644 --- a/modAionBase/test/org/aion/base/type/AddressTest.java +++ b/modAionBase/test/org/aion/base/type/AddressTest.java @@ -118,7 +118,8 @@ public void testCompare() { for (int b = 3; b < 6; b++) { try { int temp = AionAddress.wrap(addrHex[b]).compareTo(AionAddress.wrap(addrHex[b + 1])); - boolean same = AionAddress.wrap(addrHex[b]).equals(AionAddress.wrap(addrHex[b + 1])); + boolean same = + AionAddress.wrap(addrHex[b]).equals(AionAddress.wrap(addrHex[b + 1])); boolean negative = temp < 0; System.out.println("Test " + b + " & " + (b + 1) + " >> " + temp); assertFalse(same); @@ -130,7 +131,8 @@ public void testCompare() { for (int b = 6; b > 3; b--) { try { int temp = AionAddress.wrap(addrHex[b]).compareTo(AionAddress.wrap(addrHex[b - 1])); - boolean same = AionAddress.wrap(addrHex[b]).equals(AionAddress.wrap(addrHex[b - 1])); + boolean same = + AionAddress.wrap(addrHex[b]).equals(AionAddress.wrap(addrHex[b - 1])); boolean positive = temp > 0; System.out.println("Test " + b + " & " + (b - 1) + " >> " + temp); assertFalse(same); @@ -144,7 +146,8 @@ public void testCompare() { for (int b = 3; b < 6; b++) { try { int temp = AionAddress.wrap(addrByte[b]).compareTo(addrByte[b + 1]); - boolean same = AionAddress.wrap(addrByte[b]).equals(AionAddress.wrap(addrByte[b + 1])); + boolean same = + AionAddress.wrap(addrByte[b]).equals(AionAddress.wrap(addrByte[b + 1])); boolean negative = temp < 0; System.out.println("Test " + b + " & " + (b + 1) + " >> " + temp); assertFalse(same); @@ -156,7 +159,8 @@ public void testCompare() { for (int b = 6; b > 3; b--) { try { int temp = AionAddress.wrap(addrByte[b]).compareTo(addrByte[b - 1]); - boolean same = AionAddress.wrap(addrByte[b]).equals(AionAddress.wrap(addrByte[b - 1])); + boolean same = + AionAddress.wrap(addrByte[b]).equals(AionAddress.wrap(addrByte[b - 1])); boolean positive = temp > 0; System.out.println("Test " + b + " & " + (b - 1) + " >> " + temp); assertFalse(same); @@ -169,8 +173,11 @@ public void testCompare() { System.out.println("\nArray address test:"); for (int b = 3; b < 6; b++) { try { - int temp = AionAddress.wrap(addrArray[b]).compareTo(AionAddress.wrap(addrArray[b + 1])); - boolean same = AionAddress.wrap(addrArray[b]).equals(AionAddress.wrap(addrArray[b + 1])); + int temp = + AionAddress.wrap(addrArray[b]) + .compareTo(AionAddress.wrap(addrArray[b + 1])); + boolean same = + AionAddress.wrap(addrArray[b]).equals(AionAddress.wrap(addrArray[b + 1])); boolean negative = temp < 0; System.out.println("Test " + b + " & " + (b + 1) + " >> " + temp); assertFalse(same); @@ -181,8 +188,11 @@ public void testCompare() { } for (int b = 6; b > 3; b--) { try { - int temp = AionAddress.wrap(addrArray[b]).compareTo(AionAddress.wrap(addrArray[b - 1])); - boolean same = AionAddress.wrap(addrArray[b]).equals(AionAddress.wrap(addrArray[b - 1])); + int temp = + AionAddress.wrap(addrArray[b]) + .compareTo(AionAddress.wrap(addrArray[b - 1])); + boolean same = + AionAddress.wrap(addrArray[b]).equals(AionAddress.wrap(addrArray[b - 1])); boolean positive = temp > 0; System.out.println("Test " + b + " & " + (b - 1) + " >> " + temp); assertFalse(same); diff --git a/modAionImpl/src/org/aion/zero/impl/A0BCConfig.java b/modAionImpl/src/org/aion/zero/impl/A0BCConfig.java index 769b266769..3fc84b8039 100644 --- a/modAionImpl/src/org/aion/zero/impl/A0BCConfig.java +++ b/modAionImpl/src/org/aion/zero/impl/A0BCConfig.java @@ -1,6 +1,6 @@ package org.aion.zero.impl; -import org.aion.base.type.AionAddress; +import org.aion.vm.api.interfaces.Address; import org.aion.zero.impl.core.energy.AbstractEnergyStrategyLimit; public interface A0BCConfig { @@ -11,7 +11,7 @@ public interface A0BCConfig { * * @return {@code coinbase} a 32-bytes address */ - AionAddress getCoinbase(); + Address getCoinbase(); /** * Retrieve the currently set extra data for this particular node, blocks mined with this node @@ -28,7 +28,7 @@ public interface A0BCConfig { */ boolean getExitOnBlockConflict(); - AionAddress getMinerCoinbase(); + Address getMinerCoinbase(); /** Retrieves the number indicating how many blocks between each flush */ int getFlushInterval(); diff --git a/modAionImpl/src/org/aion/zero/impl/AionBlockchainImpl.java b/modAionImpl/src/org/aion/zero/impl/AionBlockchainImpl.java index 883705b5c4..7f17d07be2 100644 --- a/modAionImpl/src/org/aion/zero/impl/AionBlockchainImpl.java +++ b/modAionImpl/src/org/aion/zero/impl/AionBlockchainImpl.java @@ -134,7 +134,7 @@ public class AionBlockchainImpl implements IAionBlockchain { private boolean fork = false; - private AionAddress minerCoinbase; + private Address minerCoinbase; private byte[] minerExtraData; private Stack stateStack = new Stack<>(); @@ -160,7 +160,7 @@ private static A0BCConfig generateBCConfig(CfgAion cfgAion) { ChainConfiguration config = new ChainConfiguration(); return new A0BCConfig() { @Override - public AionAddress getCoinbase() { + public Address getCoinbase() { return cfgAion.getGenesis().getCoinbase(); } @@ -176,7 +176,7 @@ public boolean getExitOnBlockConflict() { } @Override - public AionAddress getMinerCoinbase() { + public Address getMinerCoinbase() { return AionAddress.wrap(cfgAion.getConsensus().getMinerAddress()); } @@ -1053,7 +1053,7 @@ private AionBlockSummary processBlock(AionBlock block) { } else { return new AionBlockSummary( block, - new HashMap(), + new HashMap(), new ArrayList(), new ArrayList()); } @@ -1107,7 +1107,7 @@ private RetValidPreBlock generatePreBlock(IAionBlock block) { } } - Map rewards = addReward(block, summaries); + Map rewards = addReward(block, summaries); track.flush(); @@ -1165,7 +1165,7 @@ private AionBlockSummary applyBlock(IAionBlock block) { summaries.add(summary); } - Map rewards = addReward(block, summaries); + Map rewards = addReward(block, summaries); long totalTime = System.nanoTime() - saveTime; chainStats.addBlockExecTime(totalTime); @@ -1178,10 +1178,10 @@ private AionBlockSummary applyBlock(IAionBlock block) { * * @param block object containing the header and uncles */ - private Map addReward( + private Map addReward( IAionBlock block, List summaries) { - Map rewards = new HashMap<>(); + Map rewards = new HashMap<>(); BigInteger minerReward = this.chainConfiguration.getRewardsCalculator().calculateReward(block.getHeader()); rewards.put(block.getCoinbase(), minerReward); @@ -1355,7 +1355,7 @@ public void setExitOn(long exitOn) { } @Override - public AionAddress getMinerCoinbase() { + public Address getMinerCoinbase() { return minerCoinbase; } diff --git a/modAionImpl/src/org/aion/zero/impl/AionGenesis.java b/modAionImpl/src/org/aion/zero/impl/AionGenesis.java index e4a4742ef4..0f78e6e2b4 100644 --- a/modAionImpl/src/org/aion/zero/impl/AionGenesis.java +++ b/modAionImpl/src/org/aion/zero/impl/AionGenesis.java @@ -13,6 +13,7 @@ import org.aion.mcf.types.AbstractBlockHeader; import org.aion.mcf.vm.types.DataWord; import org.aion.precompiled.ContractFactory; +import org.aion.vm.api.interfaces.Address; import org.aion.zero.db.AionContractDetailsImpl; import org.aion.zero.exceptions.HeaderStructureException; import org.aion.zero.impl.types.AionBlock; @@ -23,7 +24,7 @@ public class AionGenesis extends AionBlock { * Make this value constant for now, in the future we may move this to a more configuration * position, this indicates the address at which the storage rows are to be stored */ - protected static final AionAddress NETWORK_BALANCE_ADDRESS = + protected static final Address NETWORK_BALANCE_ADDRESS = ContractFactory.getTotalCurrencyContractAddress(); /** @@ -47,7 +48,7 @@ public class AionGenesis extends AionBlock { * Corresponds to {@link AbstractBlockHeader#getCoinbase()} that mined the first block. For * fairness, the address is set to an address that is not ever to be used */ - protected static final AionAddress GENESIS_COINBASE = AionAddress.ZERO_ADDRESS(); + protected static final Address GENESIS_COINBASE = AionAddress.ZERO_ADDRESS(); /** * Corresponds to {@link AbstractBlockHeader#getLogsBloom()} indicates the logsBloom of the @@ -104,7 +105,7 @@ public class AionGenesis extends AionBlock { protected static final long GENESIS_ENERGY_LIMIT = 10000000; /** Corresponds to {@link AionGenesis#premine} default premined accounts */ - protected static final Map GENESIS_PREMINE; + protected static final Map GENESIS_PREMINE; protected static final Map GENESIS_NETWORK_BALANCE; @@ -125,14 +126,14 @@ public class AionGenesis extends AionBlock { * bridging mechanism, we arbitrarily store all ERC20 token values as coins on an account at * address 0x100 (256). */ - private Map premine = new HashMap<>(); + private Map premine = new HashMap<>(); // TODO: verify whether setting the solution to null is okay // TODO: set energyLimit to a correct value (after genesis loader is // completed) public AionGenesis( byte[] parentHash, - AionAddress coinbase, + Address coinbase, byte[] logsBloom, byte[] difficulty, long number, @@ -153,11 +154,11 @@ public AionGenesis( energyLimit); } - public Map getPremine() { + public Map getPremine() { return premine; } - public void setPremine(Map premine) { + public void setPremine(Map premine) { this.premine = premine; } @@ -193,7 +194,7 @@ public int getChainId() { */ public static class Builder { protected byte[] parentHash; - protected AionAddress coinbase; + protected Address coinbase; protected byte[] logsBloom; protected byte[] difficulty; protected Long number; @@ -208,14 +209,14 @@ public static class Builder { protected int chainId; protected Map networkBalance; - protected Map premined; + protected Map premined; public Builder withParentHash(final byte[] parentHash) { this.parentHash = parentHash; return this; } - public Builder withCoinbase(final AionAddress coinbase) { + public Builder withCoinbase(final Address coinbase) { this.coinbase = coinbase; return this; } @@ -262,7 +263,7 @@ public Builder withChainId(final int chainId) { return this; } - public Builder addPreminedAccount(final AionAddress address, final AccountState state) { + public Builder addPreminedAccount(final Address address, final AccountState state) { if (this.premined == null) this.premined = new HashMap<>(); if (this.premined.get(address) != null) @@ -359,7 +360,7 @@ protected byte[] generateRootHash() { worldTrie.update(NETWORK_BALANCE_ADDRESS.toBytes(), networkBalanceAccount.getEncoded()); // update predefined accounts - for (Map.Entry preminedEntry : this.premined.entrySet()) { + for (Map.Entry preminedEntry : this.premined.entrySet()) { worldTrie.update( preminedEntry.getKey().toBytes(), preminedEntry.getValue().getEncoded()); } diff --git a/modAionImpl/src/org/aion/zero/impl/AionHubUtils.java b/modAionImpl/src/org/aion/zero/impl/AionHubUtils.java index e1a7b7c9a2..8a454029dd 100644 --- a/modAionImpl/src/org/aion/zero/impl/AionHubUtils.java +++ b/modAionImpl/src/org/aion/zero/impl/AionHubUtils.java @@ -3,9 +3,9 @@ import java.math.BigInteger; import java.util.Map; import org.aion.base.db.IRepositoryCache; -import org.aion.base.type.AionAddress; import org.aion.mcf.vm.types.DataWord; import org.aion.precompiled.ContractFactory; +import org.aion.vm.api.interfaces.Address; import org.aion.zero.impl.db.AionRepositoryImpl; /** {@link AionHub} functionality where a full instantiation of the class is not desirable. */ @@ -15,7 +15,7 @@ public static void buildGenesis(AionGenesis genesis, AionRepositoryImpl reposito // initialization section for network balance contract IRepositoryCache track = repository.startTracking(); - AionAddress networkBalanceAddress = ContractFactory.getTotalCurrencyContractAddress(); + Address networkBalanceAddress = ContractFactory.getTotalCurrencyContractAddress(); track.createAccount(networkBalanceAddress); for (Map.Entry addr : genesis.getNetworkBalances().entrySet()) { @@ -25,7 +25,7 @@ public static void buildGenesis(AionGenesis genesis, AionRepositoryImpl reposito new DataWord(addr.getValue()).toWrapper()); } - for (AionAddress addr : genesis.getPremine().keySet()) { + for (Address addr : genesis.getPremine().keySet()) { track.createAccount(addr); track.addBalance(addr, genesis.getPremine().get(addr).getBalance()); } diff --git a/modAionImpl/src/org/aion/zero/impl/StandaloneBlockchain.java b/modAionImpl/src/org/aion/zero/impl/StandaloneBlockchain.java index 877ee786da..9f5df5a5c2 100644 --- a/modAionImpl/src/org/aion/zero/impl/StandaloneBlockchain.java +++ b/modAionImpl/src/org/aion/zero/impl/StandaloneBlockchain.java @@ -26,6 +26,7 @@ import org.aion.mcf.valid.BlockHeaderValidator; import org.aion.mcf.vm.types.DataWord; import org.aion.precompiled.ContractFactory; +import org.aion.vm.api.interfaces.Address; import org.aion.zero.exceptions.HeaderStructureException; import org.aion.zero.impl.blockchain.ChainConfiguration; import org.aion.zero.impl.core.energy.AbstractEnergyStrategyLimit; @@ -216,7 +217,7 @@ public Bundle build() { this.a0Config == null ? new A0BCConfig() { @Override - public AionAddress getCoinbase() { + public Address getCoinbase() { return AionAddress.ZERO_ADDRESS(); } @@ -231,7 +232,7 @@ public boolean getExitOnBlockConflict() { } @Override - public AionAddress getMinerCoinbase() { + public Address getMinerCoinbase() { return AionAddress.ZERO_ADDRESS(); } @@ -316,7 +317,7 @@ public AbstractEnergyStrategyLimit getEnergyLimitStrategy() { new DataWord(key.getValue()).toWrapper()); } - for (AionAddress key : genesis.getPremine().keySet()) { + for (Address key : genesis.getPremine().keySet()) { track.createAccount(key); track.addBalance(key, genesis.getPremine().get(key).getBalance()); } @@ -369,7 +370,8 @@ public synchronized ImportResult tryToConnect(final AionBlock block) { } // TEMPORARY: here to support the ConsensusTest - public synchronized Pair tryToConnectAndFetchSummary(AionBlock block) { + public synchronized Pair tryToConnectAndFetchSummary( + AionBlock block) { return tryToConnectAndFetchSummary(block, System.currentTimeMillis() / 1000); } diff --git a/modAionImpl/src/org/aion/zero/impl/blockchain/AionImpl.java b/modAionImpl/src/org/aion/zero/impl/blockchain/AionImpl.java index 83cf669ad2..831a2e5d0d 100644 --- a/modAionImpl/src/org/aion/zero/impl/blockchain/AionImpl.java +++ b/modAionImpl/src/org/aion/zero/impl/blockchain/AionImpl.java @@ -21,6 +21,7 @@ import org.aion.vm.BulkExecutor; import org.aion.vm.ExecutionBatch; import org.aion.vm.PostExecutionWork; +import org.aion.vm.api.interfaces.Address; import org.aion.zero.impl.AionHub; import org.aion.zero.impl.config.CfgAion; import org.aion.zero.impl.tx.TxCollector; @@ -100,7 +101,7 @@ public void close() { @Override public AionTransaction createTransaction( - BigInteger nonce, AionAddress to, BigInteger value, byte[] data) { + BigInteger nonce, Address to, BigInteger value, byte[] data) { byte[] nonceBytes = ByteUtil.bigIntegerToBytes(nonce); byte[] valueBytes = ByteUtil.bigIntegerToBytes(value); return new AionTransaction(nonceBytes, to, valueBytes, data); @@ -285,7 +286,7 @@ public Optional getInitialStartingBlockNumber() { // assumes a correctly formatted block number @Override - public Optional getAccountState(AionAddress address, long blockNumber) { + public Optional getAccountState(Address address, long blockNumber) { try { byte[] stateRoot = this.aionHub.getBlockStore().getChainBlockByNumber(blockNumber).getStateRoot(); @@ -307,7 +308,7 @@ public Optional getAccountState(AionAddress address, long blockNum // assumes a correctly formatted blockHash @Override - public Optional getAccountState(AionAddress address, byte[] blockHash) { + public Optional getAccountState(Address address, byte[] blockHash) { try { byte[] stateRoot = this.aionHub.getBlockchain().getBlockByHash(blockHash).getStateRoot(); @@ -328,7 +329,7 @@ public Optional getAccountState(AionAddress address, byte[] blockH } @Override - public Optional getAccountState(AionAddress address) { + public Optional getAccountState(Address address) { try { byte[] stateRoot = this.aionHub.getBlockchain().getBestBlock().getStateRoot(); AccountState account = @@ -348,7 +349,7 @@ public Optional getAccountState(AionAddress address) { } @Override - public Optional getCode(AionAddress address) { + public Optional getCode(Address address) { byte[] code = this.aionHub.getRepository().getCode(address); if (code == null) return Optional.empty(); return Optional.of(new ByteArrayWrapper(code)); diff --git a/modAionImpl/src/org/aion/zero/impl/blockchain/ChainConfiguration.java b/modAionImpl/src/org/aion/zero/impl/blockchain/ChainConfiguration.java index 420780750a..bad21ca04a 100644 --- a/modAionImpl/src/org/aion/zero/impl/blockchain/ChainConfiguration.java +++ b/modAionImpl/src/org/aion/zero/impl/blockchain/ChainConfiguration.java @@ -2,7 +2,6 @@ import java.math.BigInteger; import java.util.Arrays; -import org.aion.base.type.AionAddress; import org.aion.equihash.OptimizedEquiValidator; import org.aion.mcf.blockchain.IBlockConstants; import org.aion.mcf.blockchain.IChainCfg; @@ -14,6 +13,7 @@ import org.aion.mcf.valid.GrandParentBlockHeaderValidator; import org.aion.mcf.valid.ParentBlockHeaderValidator; import org.aion.mcf.valid.TimeStampRule; +import org.aion.vm.api.interfaces.Address; import org.aion.zero.api.BlockConstants; import org.aion.zero.impl.config.CfgAion; import org.aion.zero.impl.core.DiffCalc; @@ -44,7 +44,7 @@ public class ChainConfiguration implements IChainCfg getAccountsKeys() { + public Set
getAccountsKeys() { return null; } @@ -113,7 +113,7 @@ public Set getFullAddressSet() { return worldState.keySet(); } - public BigInteger addBalance(AionAddress addr, BigInteger value) { + public BigInteger addBalance(Address addr, BigInteger value) { AccountState account = getAccountState(addr); if (account == null) { @@ -121,12 +121,12 @@ public BigInteger addBalance(AionAddress addr, BigInteger value) { } BigInteger result = account.addToBalance(value); - worldState.put(addr.toByteArrayWrapper(), account); + worldState.put(ByteArrayWrapper.wrap(addr.toBytes()), account); return result; } - public BigInteger getBalance(AionAddress addr) { + public BigInteger getBalance(Address addr) { AccountState account = getAccountState(addr); if (account == null) { @@ -136,7 +136,7 @@ public BigInteger getBalance(AionAddress addr) { return account.getBalance(); } - public ByteArrayWrapper getStorageValue(AionAddress addr, ByteArrayWrapper key) { + public ByteArrayWrapper getStorageValue(Address addr, ByteArrayWrapper key) { IContractDetails details = getContractDetails(addr); ByteArrayWrapper value = (details == null) ? null : details.get(key); @@ -149,7 +149,7 @@ public ByteArrayWrapper getStorageValue(AionAddress addr, ByteArrayWrapper key) return value; } - public void addStorageRow(AionAddress addr, ByteArrayWrapper key, ByteArrayWrapper value) { + public void addStorageRow(Address addr, ByteArrayWrapper key, ByteArrayWrapper value) { IContractDetails details = getContractDetails(addr); if (details == null) { @@ -157,10 +157,10 @@ public void addStorageRow(AionAddress addr, ByteArrayWrapper key, ByteArrayWrapp details = getContractDetails(addr); } details.put(key, value); - detailsDB.put(addr.toByteArrayWrapper(), details); + detailsDB.put(ByteArrayWrapper.wrap(addr.toBytes()), details); } - public byte[] getCode(AionAddress addr) { + public byte[] getCode(Address addr) { IContractDetails details = getContractDetails(addr); if (details == null) { @@ -170,7 +170,7 @@ public byte[] getCode(AionAddress addr) { return details.getCode(); } - public void saveCode(AionAddress addr, byte[] code) { + public void saveCode(Address addr, byte[] code) { IContractDetails details = getContractDetails(addr); if (details == null) { @@ -179,10 +179,10 @@ public void saveCode(AionAddress addr, byte[] code) { } details.setCode(code); - detailsDB.put(addr.toByteArrayWrapper(), details); + detailsDB.put(ByteArrayWrapper.wrap(addr.toBytes()), details); } - public BigInteger getNonce(AionAddress addr) { + public BigInteger getNonce(Address addr) { AccountState account = getAccountState(addr); if (account == null) { @@ -192,7 +192,7 @@ public BigInteger getNonce(AionAddress addr) { return account.getNonce(); } - public BigInteger increaseNonce(AionAddress addr) { + public BigInteger increaseNonce(Address addr) { AccountState account = getAccountState(addr); if (account == null) { @@ -200,12 +200,12 @@ public BigInteger increaseNonce(AionAddress addr) { } account.incrementNonce(); - worldState.put(addr.toByteArrayWrapper(), account); + worldState.put(ByteArrayWrapper.wrap(addr.toBytes()), account); return account.getNonce(); } - public BigInteger setNonce(AionAddress addr, BigInteger nonce) { + public BigInteger setNonce(Address addr, BigInteger nonce) { AccountState account = getAccountState(addr); @@ -214,36 +214,36 @@ public BigInteger setNonce(AionAddress addr, BigInteger nonce) { } account.setNonce(nonce); - worldState.put(addr.toByteArrayWrapper(), account); + worldState.put(ByteArrayWrapper.wrap(addr.toBytes()), account); return account.getNonce(); } - public void delete(AionAddress addr) { - worldState.remove(addr.toByteArrayWrapper()); - detailsDB.remove(addr.toByteArrayWrapper()); + public void delete(Address addr) { + worldState.remove(ByteArrayWrapper.wrap(addr.toBytes())); + detailsDB.remove(ByteArrayWrapper.wrap(addr.toBytes())); } - public IContractDetails getContractDetails(AionAddress addr) { + public IContractDetails getContractDetails(Address addr) { - return detailsDB.get(addr.toByteArrayWrapper()); + return detailsDB.get(ByteArrayWrapper.wrap(addr.toBytes())); } - public AccountState getAccountState(AionAddress addr) { - return worldState.get((addr.toByteArrayWrapper())); + public AccountState getAccountState(Address addr) { + return worldState.get((ByteArrayWrapper.wrap(addr.toBytes()))); } - public AccountState createAccount(AionAddress addr) { + public AccountState createAccount(Address addr) { AccountState accountState = new AccountState(); - worldState.put(addr.toByteArrayWrapper(), accountState); + worldState.put(ByteArrayWrapper.wrap(addr.toBytes()), accountState); IContractDetails contractDetails = this.cfg.contractDetailsImpl(); - detailsDB.put(addr.toByteArrayWrapper(), contractDetails); + detailsDB.put(ByteArrayWrapper.wrap(addr.toBytes()), contractDetails); return accountState; } - public boolean isExist(AionAddress addr) { + public boolean isExist(Address addr) { return getAccountState(addr) != null; } @@ -252,7 +252,7 @@ public byte[] getRoot() { } public void loadAccount( - AionAddress addr, + Address addr, HashMap cacheAccounts, HashMap cacheDetails) { @@ -271,7 +271,7 @@ public void loadAccount( details = new ContractDetailsCacheImpl(details); } - cacheAccounts.put(addr.toByteArrayWrapper(), account); - cacheDetails.put(addr.toByteArrayWrapper(), details); + cacheAccounts.put(ByteArrayWrapper.wrap(addr.toBytes()), account); + cacheDetails.put(ByteArrayWrapper.wrap(addr.toBytes()), details); } } diff --git a/modAionImpl/src/org/aion/zero/impl/query/StateQueryInterface.java b/modAionImpl/src/org/aion/zero/impl/query/StateQueryInterface.java index c82d4f0566..a201f6bcb6 100644 --- a/modAionImpl/src/org/aion/zero/impl/query/StateQueryInterface.java +++ b/modAionImpl/src/org/aion/zero/impl/query/StateQueryInterface.java @@ -1,16 +1,16 @@ package org.aion.zero.impl.query; import java.util.Optional; -import org.aion.base.type.AionAddress; import org.aion.base.util.ByteArrayWrapper; import org.aion.mcf.core.AccountState; +import org.aion.vm.api.interfaces.Address; public interface StateQueryInterface { - Optional getAccountState(AionAddress address, long blockNumber); + Optional getAccountState(Address address, long blockNumber); - Optional getAccountState(AionAddress address, byte[] blockHash); + Optional getAccountState(Address address, byte[] blockHash); - Optional getAccountState(AionAddress address); + Optional getAccountState(Address address); - Optional getCode(AionAddress address); + Optional getCode(Address address); } diff --git a/modAionImpl/src/org/aion/zero/impl/types/AionBlock.java b/modAionImpl/src/org/aion/zero/impl/types/AionBlock.java index 936ed05b2c..4b001aac68 100644 --- a/modAionImpl/src/org/aion/zero/impl/types/AionBlock.java +++ b/modAionImpl/src/org/aion/zero/impl/types/AionBlock.java @@ -4,7 +4,6 @@ import java.util.Arrays; import java.util.List; import java.util.concurrent.CopyOnWriteArrayList; -import org.aion.base.type.AionAddress; import org.aion.base.util.ByteUtil; import org.aion.base.util.Hex; import org.aion.log.AionLoggerFactory; @@ -15,6 +14,7 @@ import org.aion.rlp.RLP; import org.aion.rlp.RLPElement; import org.aion.rlp.RLPList; +import org.aion.vm.api.interfaces.Address; import org.aion.zero.exceptions.HeaderStructureException; import org.aion.zero.types.A0BlockHeader; import org.aion.zero.types.AionTransaction; @@ -76,7 +76,7 @@ public AionBlock(A0BlockHeader header, List transactionsList) { public AionBlock( byte[] parentHash, - AionAddress coinbase, + Address coinbase, byte[] logsBloom, byte[] difficulty, long number, @@ -125,7 +125,7 @@ public AionBlock( */ protected AionBlock( byte[] parentHash, - AionAddress coinbase, + Address coinbase, byte[] logsBloom, byte[] difficulty, long number, @@ -190,7 +190,7 @@ public byte[] getParentHash() { return this.header.getParentHash(); } - public AionAddress getCoinbase() { + public Address getCoinbase() { parseRLP(); return this.header.getCoinbase(); } diff --git a/modAionImpl/src/org/aion/zero/impl/types/AionBlockSummary.java b/modAionImpl/src/org/aion/zero/impl/types/AionBlockSummary.java index 1555555456..81af2b34bd 100644 --- a/modAionImpl/src/org/aion/zero/impl/types/AionBlockSummary.java +++ b/modAionImpl/src/org/aion/zero/impl/types/AionBlockSummary.java @@ -3,9 +3,9 @@ import java.math.BigInteger; import java.util.List; import java.util.Map; -import org.aion.base.type.AionAddress; import org.aion.base.type.IBlockSummary; import org.aion.mcf.types.AbstractBlockSummary; +import org.aion.vm.api.interfaces.Address; import org.aion.zero.types.AionTransaction; import org.aion.zero.types.AionTxExecSummary; import org.aion.zero.types.AionTxReceipt; @@ -22,7 +22,7 @@ public class AionBlockSummary public AionBlockSummary( IAionBlock block, - Map rewards, + Map rewards, List receipts, List summaries) { this.block = block; diff --git a/modAionImpl/src/org/aion/zero/impl/types/RetValidPreBlock.java b/modAionImpl/src/org/aion/zero/impl/types/RetValidPreBlock.java index e98e7662be..0e238c33ef 100644 --- a/modAionImpl/src/org/aion/zero/impl/types/RetValidPreBlock.java +++ b/modAionImpl/src/org/aion/zero/impl/types/RetValidPreBlock.java @@ -3,7 +3,7 @@ import java.math.BigInteger; import java.util.List; import java.util.Map; -import org.aion.base.type.AionAddress; +import org.aion.vm.api.interfaces.Address; import org.aion.zero.types.AionTransaction; import org.aion.zero.types.AionTxExecSummary; import org.aion.zero.types.AionTxReceipt; @@ -11,13 +11,13 @@ public class RetValidPreBlock { public final List txs; - public final Map rewards; + public final Map rewards; public final List receipts; public final List summaries; public RetValidPreBlock( List txs, - Map rewards, + Map rewards, List receipts, List summaries) { this.txs = txs; diff --git a/modAionImpl/test/org/aion/db/AionContractDetailsTest.java b/modAionImpl/test/org/aion/db/AionContractDetailsTest.java index 7e137385f4..676963fcf4 100644 --- a/modAionImpl/test/org/aion/db/AionContractDetailsTest.java +++ b/modAionImpl/test/org/aion/db/AionContractDetailsTest.java @@ -17,6 +17,7 @@ import org.aion.db.impl.DatabaseFactory; import org.aion.mcf.config.CfgPrune; import org.aion.mcf.vm.types.DataWord; +import org.aion.vm.api.interfaces.Address; import org.aion.zero.db.AionContractDetailsImpl; import org.aion.zero.impl.db.AionRepositoryImpl; import org.aion.zero.impl.db.ContractDetailsAion; @@ -110,7 +111,7 @@ public void test_2() throws Exception { byte[] code = ByteUtil.hexStringToBytes( "7c0100000000000000000000000000000000000000000000000000000000600035046333d546748114610065578063430fe5f01461007c5780634d432c1d1461008d578063501385b2146100b857806357eb3b30146100e9578063dbc7df61146100fb57005b6100766004356024356044356102f0565b60006000f35b61008760043561039e565b60006000f35b610098600435610178565b8073ffffffffffffffffffffffffffffffffffffffff1660005260206000f35b6100c96004356024356044356101a0565b8073ffffffffffffffffffffffffffffffffffffffff1660005260206000f35b6100f1610171565b8060005260206000f35b610106600435610133565b8360005282602052816040528073ffffffffffffffffffffffffffffffffffffffff1660605260806000f35b5b60006020819052908152604090208054600182015460028301546003909301549192909173ffffffffffffffffffffffffffffffffffffffff1684565b5b60015481565b5b60026020526000908152604090205473ffffffffffffffffffffffffffffffffffffffff1681565b73ffffffffffffffffffffffffffffffffffffffff831660009081526020819052604081206002015481908302341080156101fe575073ffffffffffffffffffffffffffffffffffffffff8516600090815260208190526040812054145b8015610232575073ffffffffffffffffffffffffffffffffffffffff85166000908152602081905260409020600101548390105b61023b57610243565b3391506102e8565b6101966103ca60003973ffffffffffffffffffffffffffffffffffffffff3381166101965285166101b68190526000908152602081905260408120600201546101d6526101f68490526102169080f073ffffffffffffffffffffffffffffffffffffffff8616600090815260208190526040902060030180547fffffffffffffffffffffffff0000000000000000000000000000000000000000168217905591508190505b509392505050565b73ffffffffffffffffffffffffffffffffffffffff33166000908152602081905260408120548190821461032357610364565b60018054808201909155600090815260026020526040902080547fffffffffffffffffffffffff000000000000000000000000000000000000000016331790555b50503373ffffffffffffffffffffffffffffffffffffffff1660009081526020819052604090209081556001810192909255600290910155565b3373ffffffffffffffffffffffffffffffffffffffff166000908152602081905260409020600201555600608061019660043960048051602451604451606451600080547fffffffffffffffffffffffff0000000000000000000000000000000000000000908116909517815560018054909516909317909355600355915561013390819061006390396000f3007c0100000000000000000000000000000000000000000000000000000000600035046347810fe381146100445780637e4a1aa81461005557806383d2421b1461006957005b61004f6004356100ab565b60006000f35b6100636004356024356100fc565b60006000f35b61007460043561007a565b60006000f35b6001543373ffffffffffffffffffffffffffffffffffffffff9081169116146100a2576100a8565b60078190555b50565b73ffffffffffffffffffffffffffffffffffffffff8116600090815260026020526040902080547fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff0016600117905550565b6001543373ffffffffffffffffffffffffffffffffffffffff9081169116146101245761012f565b600582905560068190555b505056"); - AionAddress address = AionAddress.wrap(RandomUtils.nextBytes(AionAddress.SIZE)); + Address address = AionAddress.wrap(RandomUtils.nextBytes(Address.SIZE)); byte[] key_0 = ByteUtil.hexStringToBytes("18d63b70aa690ad37cb50908746c9a55"); byte[] val_0 = ByteUtil.hexStringToBytes("00000000000000000000000000000064"); @@ -240,7 +241,7 @@ public void test_2() throws Exception { @Test public void testExternalStorageSerialization() { - AionAddress address = AionAddress.wrap(RandomUtils.nextBytes(AionAddress.SIZE)); + Address address = AionAddress.wrap(RandomUtils.nextBytes(Address.SIZE)); byte[] code = RandomUtils.nextBytes(512); Map elements = new HashMap<>(); @@ -286,7 +287,7 @@ public void testExternalStorageSerialization() { @Test public void testExternalStorageTransition() { - AionAddress address = AionAddress.wrap(RandomUtils.nextBytes(AionAddress.SIZE)); + Address address = AionAddress.wrap(RandomUtils.nextBytes(Address.SIZE)); byte[] code = RandomUtils.nextBytes(512); Map elements = new HashMap<>(); diff --git a/modAionImpl/test/org/aion/db/DoubleDataWordTest.java b/modAionImpl/test/org/aion/db/DoubleDataWordTest.java index 77a8d96063..444bbd952d 100644 --- a/modAionImpl/test/org/aion/db/DoubleDataWordTest.java +++ b/modAionImpl/test/org/aion/db/DoubleDataWordTest.java @@ -19,6 +19,7 @@ import org.aion.mcf.db.IBlockStoreBase; import org.aion.mcf.vm.types.DataWord; import org.aion.mcf.vm.types.DoubleDataWord; +import org.aion.vm.api.interfaces.Address; import org.aion.zero.db.AionRepositoryCache; import org.aion.zero.impl.db.AionRepositoryImpl; import org.aion.zero.impl.db.ContractDetailsAion; @@ -32,7 +33,7 @@ public class DoubleDataWordTest { private IRepository repo; private IRepositoryCache> track; private Random rand; - private AionAddress addr; + private Address addr; @Before public void setup() { diff --git a/modAionImpl/test/org/aion/equihash/benchmark/BatchHeaderBenchmark.java b/modAionImpl/test/org/aion/equihash/benchmark/BatchHeaderBenchmark.java index f8cf34bb47..4bc2a19c0a 100644 --- a/modAionImpl/test/org/aion/equihash/benchmark/BatchHeaderBenchmark.java +++ b/modAionImpl/test/org/aion/equihash/benchmark/BatchHeaderBenchmark.java @@ -1,6 +1,6 @@ // package org.aion.equihash.benchmark; // -// import org.aion.base.type.Address; +// import org.aion.base.type.AionAddress; // import org.aion.base.util.ByteUtil; // import org.aion.equihash.EquiUtils; // import org.aion.equihash.OptimizedEquiValidator; diff --git a/modAionImpl/test/org/aion/zero/impl/BlockchainAccountStateBenchmark.java b/modAionImpl/test/org/aion/zero/impl/BlockchainAccountStateBenchmark.java index 8ebfa52c7e..22211fce14 100644 --- a/modAionImpl/test/org/aion/zero/impl/BlockchainAccountStateBenchmark.java +++ b/modAionImpl/test/org/aion/zero/impl/BlockchainAccountStateBenchmark.java @@ -16,6 +16,7 @@ import org.aion.db.impl.DBVendor; import org.aion.db.utils.FileUtils; import org.aion.mcf.core.ImportResult; +import org.aion.vm.api.interfaces.Address; import org.aion.zero.impl.types.AionBlock; import org.aion.zero.impl.types.AionTxInfo; import org.aion.zero.types.AionTransaction; @@ -162,7 +163,7 @@ private static AionBlock createBundleAndCheck( // create 400 transactions per bundle // byte[] nonce, Address to, byte[] value, byte[] data, long nrg, long nrgPrice for (int i = 0; i < 400; i++) { - AionAddress destAddr = new AionAddress(HashUtil.h256(accountNonce.toByteArray())); + Address destAddr = new AionAddress(HashUtil.h256(accountNonce.toByteArray())); AionTransaction sendTransaction = new AionTransaction( accountNonce.toByteArray(), @@ -209,7 +210,7 @@ public void testExpandOneAccountStorage() throws InterruptedException { AionTxInfo info = bc.getTransactionInfo(res.getRight()); assertThat(info.getReceipt().isValid()).isTrue(); - AionAddress contractAddress = info.getReceipt().getTransaction().getContractAddress(); + Address contractAddress = info.getReceipt().getTransaction().getContractAddress(); byte[] contractCode = bc.getRepository() @@ -251,7 +252,7 @@ private static AionBlock createContractBundle( final StandaloneBlockchain bc, final ECKey key, final AionBlock parentBlock, - final AionAddress contractAddress) { + final Address contractAddress) { BigInteger accountNonce = bc.getRepository().getNonce(new AionAddress(key.getAddress())); List transactions = new ArrayList<>(); diff --git a/modAionImpl/test/org/aion/zero/impl/BlockchainAccountStateTest.java b/modAionImpl/test/org/aion/zero/impl/BlockchainAccountStateTest.java index 8249d31b4e..101b177453 100644 --- a/modAionImpl/test/org/aion/zero/impl/BlockchainAccountStateTest.java +++ b/modAionImpl/test/org/aion/zero/impl/BlockchainAccountStateTest.java @@ -9,6 +9,7 @@ import org.aion.crypto.ECKey; import org.aion.crypto.HashUtil; import org.aion.mcf.core.ImportResult; +import org.aion.vm.api.interfaces.Address; import org.aion.zero.impl.types.AionBlock; import org.aion.zero.types.AionTransaction; import org.junit.Ignore; @@ -49,7 +50,7 @@ private static AionBlock createBundleAndCheck( // create 400 transactions per bundle // byte[] nonce, Address to, byte[] value, byte[] data, long nrg, long nrgPrice for (int i = 0; i < 400; i++) { - AionAddress destAddr = new AionAddress(HashUtil.h256(accountNonce.toByteArray())); + Address destAddr = new AionAddress(HashUtil.h256(accountNonce.toByteArray())); AionTransaction sendTransaction = new AionTransaction( accountNonce.toByteArray(), @@ -113,7 +114,7 @@ private static AionBlock createContractBundle( // create 400 transactions per bundle // byte[] nonce, Address to, byte[] value, byte[] data, long nrg, long nrgPrice for (int i = 0; i < 400; i++) { - AionAddress destAddr = new AionAddress(HashUtil.h256(accountNonce.toByteArray())); + Address destAddr = new AionAddress(HashUtil.h256(accountNonce.toByteArray())); AionTransaction sendTransaction = new AionTransaction( accountNonce.toByteArray(), diff --git a/modAionImpl/test/org/aion/zero/impl/BlockchainEnergyTest.java b/modAionImpl/test/org/aion/zero/impl/BlockchainEnergyTest.java index e1066c6d4b..38fef24bc1 100644 --- a/modAionImpl/test/org/aion/zero/impl/BlockchainEnergyTest.java +++ b/modAionImpl/test/org/aion/zero/impl/BlockchainEnergyTest.java @@ -9,6 +9,7 @@ import org.aion.base.type.AionAddress; import org.aion.base.util.ByteUtil; import org.aion.mcf.core.ImportResult; +import org.aion.vm.api.interfaces.Address; import org.aion.zero.impl.types.AionBlock; import org.aion.zero.types.AionTransaction; import org.junit.Test; @@ -33,8 +34,9 @@ public void testConsistentEnergyUsage() { @Test public void testEnergyUsageRecorded() { final int DEFAULT_TX_AMOUNT = 21000; - final AionAddress RECEIPT_ADDR = - AionAddress.wrap("CAFECAFECAFECAFECAFECAFECAFECAFECAFECAFECAFECAFECAFECAFECAFECAFE"); + final Address RECEIPT_ADDR = + AionAddress.wrap( + "CAFECAFECAFECAFECAFECAFECAFECAFECAFECAFECAFECAFECAFECAFECAFECAFE"); StandaloneBlockchain.Bundle bundle = new StandaloneBlockchain.Builder() diff --git a/modAionImpl/test/org/aion/zero/impl/BlockchainIntegrationTest.java b/modAionImpl/test/org/aion/zero/impl/BlockchainIntegrationTest.java index 14a2da34ea..479abbd0b1 100644 --- a/modAionImpl/test/org/aion/zero/impl/BlockchainIntegrationTest.java +++ b/modAionImpl/test/org/aion/zero/impl/BlockchainIntegrationTest.java @@ -11,6 +11,7 @@ import org.aion.crypto.ECKey; import org.aion.crypto.HashUtil; import org.aion.mcf.core.ImportResult; +import org.aion.vm.api.interfaces.Address; import org.aion.zero.impl.blockchain.ChainConfiguration; import org.aion.zero.impl.types.AionBlock; import org.aion.zero.types.AionTransaction; @@ -70,7 +71,7 @@ public void testCreateNewEmptyBlock() { @Test public void testSimpleFailedTransactionInsufficientBalance() { // generate a recipient - final AionAddress receiverAddress = + final Address receiverAddress = AionAddress.wrap( ByteUtil.hexStringToBytes( "CAFECAFECAFECAFECAFECAFECAFECAFECAFECAFECAFECAFECAFECAFECAFECAFE")); @@ -105,7 +106,7 @@ public void testSimpleFailedTransactionInsufficientBalance() { @Test public void testSimpleOneTokenBalanceTransfer() { // generate a recipient - final AionAddress receiverAddress = + final Address receiverAddress = AionAddress.wrap( ByteUtil.hexStringToBytes( "CAFECAFECAFECAFECAFECAFECAFECAFECAFECAFECAFECAFECAFECAFECAFECAFE")); @@ -169,7 +170,7 @@ public void testAppendIncorrectTimestampBlock() { @Test public void testPruningEnabledBalanceTransfer() { // generate a recipient - final AionAddress receiverAddress = + final Address receiverAddress = AionAddress.wrap( ByteUtil.hexStringToBytes( "CAFECAFECAFECAFECAFECAFECAFECAFECAFECAFECAFECAFECAFECAFECAFECAFE")); @@ -304,7 +305,7 @@ public void testBlockContextCreation() { // no transaction so fee should be zero assertThat(context.transactionFee).isEqualTo(BigInteger.ZERO); - AionAddress beneficiary = context.block.getCoinbase(); + Address beneficiary = context.block.getCoinbase(); ImportResult result = bc.tryToConnect(context.block); // check that the correct amount was stored diff --git a/modAionImpl/test/org/aion/zero/impl/BlockchainRewardTest.java b/modAionImpl/test/org/aion/zero/impl/BlockchainRewardTest.java index e28884c434..987ec84fda 100644 --- a/modAionImpl/test/org/aion/zero/impl/BlockchainRewardTest.java +++ b/modAionImpl/test/org/aion/zero/impl/BlockchainRewardTest.java @@ -4,9 +4,9 @@ import java.math.BigInteger; import java.util.Collections; -import org.aion.base.type.AionAddress; import org.aion.mcf.blockchain.IBlockConstants; import org.aion.mcf.core.ImportResult; +import org.aion.vm.api.interfaces.Address; import org.aion.zero.api.BlockConstants; import org.aion.zero.impl.types.AionBlock; import org.junit.Ignore; @@ -38,7 +38,7 @@ public void testBlockchainRewardMonotonicallyIncreasing() { ImportResult res = bc.tryToConnect(block); assertThat(res).isEqualTo(ImportResult.IMPORTED_BEST); - AionAddress coinbase = block.getCoinbase(); + Address coinbase = block.getCoinbase(); BigInteger previousBalance = bc.getRepository().getBalance(coinbase); // first block already sealed diff --git a/modAionImpl/test/org/aion/zero/impl/BlockchainTestUtils.java b/modAionImpl/test/org/aion/zero/impl/BlockchainTestUtils.java index 467d471440..50c08c6ba5 100644 --- a/modAionImpl/test/org/aion/zero/impl/BlockchainTestUtils.java +++ b/modAionImpl/test/org/aion/zero/impl/BlockchainTestUtils.java @@ -12,6 +12,7 @@ import org.aion.crypto.ECKeyFac; import org.aion.crypto.HashUtil; import org.aion.mcf.core.ImportResult; +import org.aion.vm.api.interfaces.Address; import org.aion.zero.impl.db.AionRepositoryImpl; import org.aion.zero.impl.types.AionBlock; import org.aion.zero.types.AionTransaction; @@ -56,7 +57,7 @@ public static List generateTransactions( BigInteger accountNonce = nonces.get(key); // generate a random address - AionAddress destAddr = new AionAddress(HashUtil.h256(accountNonce.toByteArray())); + Address destAddr = new AionAddress(HashUtil.h256(accountNonce.toByteArray())); AionTransaction newTx = new AionTransaction( accountNonce.toByteArray(), diff --git a/modAionImpl/test/org/aion/zero/impl/ConsensusTest.java b/modAionImpl/test/org/aion/zero/impl/ConsensusTest.java index be37095322..afa63a4770 100644 --- a/modAionImpl/test/org/aion/zero/impl/ConsensusTest.java +++ b/modAionImpl/test/org/aion/zero/impl/ConsensusTest.java @@ -13,6 +13,7 @@ import org.aion.mcf.core.ImportResult; import org.aion.util.bytes.ByteUtil; import org.aion.util.conversions.Hex; +import org.aion.vm.api.interfaces.Address; import org.aion.zero.impl.types.AionBlock; import org.aion.zero.impl.types.AionBlockSummary; import org.aion.zero.types.AionTransaction; @@ -35,11 +36,11 @@ * block of transactions. */ public class ConsensusTest { - private static final AionAddress CONTRACT = + private static final Address CONTRACT = AionAddress.wrap("a04272bb5f935fb170baf2998cb25dd15cc5794e7c5bac7241bec00c4971c7f8"); - private static final AionAddress OWNER = + private static final Address OWNER = AionAddress.wrap("a05577af5a82aa86bb2f4247e3f809bd0d396d45ec3c4602d5824962d21b1679"); - private static final AionAddress OTHER = + private static final Address OTHER = AionAddress.wrap("a05577af5a82aa86bb2f4247e3f809bd0d396d45ec3c4602d5824962d21b1678"); private static final byte[] PRIVATE_KEY = Hex.decode( @@ -352,7 +353,7 @@ private static AionTransaction getDeployTransaction() { return transaction; } - /** Calls the function: addOwner(AionAddress) in Wallet.sol */ + /** Calls the function: addOwner(Address) in Wallet.sol */ private static AionTransaction getTransactionThatCallsAddOwner() { ECKey key = ECKeyFac.inst().fromPrivate(PRIVATE_KEY); byte[] callData = ByteUtil.merge(Hex.decode("7065cb48"), OWNER.toBytes()); @@ -369,11 +370,11 @@ private static AionTransaction getTransactionThatCallsAddOwner() { } /** - * Calls the function: isOwner(AionAddress) in Wallet.sol + * Calls the function: isOwner(Address) in Wallet.sol * - *

The AionAddress that is being queried is 'owner'. + *

The Address that is being queried is 'owner'. */ - private static AionTransaction getTransactionThatCallsIsOwner(AionAddress owner, int nonce) { + private static AionTransaction getTransactionThatCallsIsOwner(Address owner, int nonce) { ECKey key = ECKeyFac.inst().fromPrivate(PRIVATE_KEY); byte[] callData = ByteUtil.merge(Hex.decode("2f54bf6e"), owner.toBytes()); AionTransaction transaction = @@ -389,7 +390,7 @@ private static AionTransaction getTransactionThatCallsIsOwner(AionAddress owner, } /** - * Calls the function: isOwner(AionAddress) in Wallet.sol + * Calls the function: isOwner(Address) in Wallet.sol * *

The energy limit provided to this function is exactly 1 energy unit short of being able to * run the transaction. As such, it fails with an OUT_OF_NRG error. diff --git a/modAionImpl/test/org/aion/zero/impl/GenesisSpecificationTest.java b/modAionImpl/test/org/aion/zero/impl/GenesisSpecificationTest.java index f7135bf495..9a02d2c6a0 100644 --- a/modAionImpl/test/org/aion/zero/impl/GenesisSpecificationTest.java +++ b/modAionImpl/test/org/aion/zero/impl/GenesisSpecificationTest.java @@ -10,6 +10,7 @@ import org.aion.base.util.ByteUtil; import org.aion.crypto.HashUtil; import org.aion.mcf.core.AccountState; +import org.aion.vm.api.interfaces.Address; import org.aion.zero.exceptions.HeaderStructureException; import org.junit.Test; @@ -44,11 +45,11 @@ public void defaultGenesisBlockTest() throws HeaderStructureException { .isEqualTo(new BigInteger(1, AionGenesis.GENESIS_DIFFICULTY)); assertThat(genesis.getTransactionsList().isEmpty()).isEqualTo(true); - Map premined = genesis.getPremine(); - Set keySet = premined.keySet(); + Map premined = genesis.getPremine(); + Set

keySet = premined.keySet(); // default set - Set defaultKeySet = AionGenesis.GENESIS_PREMINE.keySet(); + Set
defaultKeySet = AionGenesis.GENESIS_PREMINE.keySet(); assertThat(defaultKeySet.equals(keySet)).isEqualTo(true); } @@ -70,7 +71,7 @@ public void overrideGenesisBlockTest() throws HeaderStructureException { BigInteger overrideValue = BigInteger.valueOf(1337); AccountState defaultAccountState = new AccountState(overrideValue, overrideValue); - HashSet accountStateSet = new HashSet<>(); + HashSet
accountStateSet = new HashSet<>(); accountStateSet.add(AionAddress.wrap(overrideHash)); genesisBuilder diff --git a/modAionImpl/test/org/aion/zero/impl/GenesisTestNetJsonTest.java b/modAionImpl/test/org/aion/zero/impl/GenesisTestNetJsonTest.java index e7e33d3f7f..e498b758c4 100644 --- a/modAionImpl/test/org/aion/zero/impl/GenesisTestNetJsonTest.java +++ b/modAionImpl/test/org/aion/zero/impl/GenesisTestNetJsonTest.java @@ -10,6 +10,7 @@ import org.aion.base.type.AionAddress; import org.aion.base.util.ByteUtil; import org.aion.mcf.core.AccountState; +import org.aion.vm.api.interfaces.Address; import org.aion.zero.exceptions.HeaderStructureException; import org.junit.BeforeClass; import org.junit.Test; @@ -46,10 +47,10 @@ public static void loadFile() { public void testNetJsonLoad() throws Exception { if (genesis == null) throw new Exception("did not properly load genesis file"); - Map premineAccounts = genesis.getPremine(); + Map premineAccounts = genesis.getPremine(); - AionAddress[] accString = - new AionAddress[] { + Address[] accString = + new Address[] { AionAddress.wrap( "0xa0483412e8c8e769df037231d336e96f7f6d843cf7224c3d8fbe0ec7cdc12ac6"), AionAddress.wrap( @@ -74,10 +75,11 @@ public void testNetJsonLoad() throws Exception { "0xa0f3defb01b531c5a28680eb928e79ea18bc155f1060e1d923d660d74883518b") }; - AionAddress tokenAddress = - new AionAddress("0xa02198c9192bb89e9b2e8536d96cbf287fde80625afcf1a5e5632e23c1260d61"); + Address tokenAddress = + new AionAddress( + "0xa02198c9192bb89e9b2e8536d96cbf287fde80625afcf1a5e5632e23c1260d61"); - for (AionAddress a : accString) { + for (Address a : accString) { assertThat(premineAccounts.containsKey(a)).isTrue(); AccountState acc = premineAccounts.get(a); diff --git a/modAionImpl/test/org/aion/zero/impl/PendingStateTest.java b/modAionImpl/test/org/aion/zero/impl/PendingStateTest.java index 83b2e5d7d1..2aaede7a99 100644 --- a/modAionImpl/test/org/aion/zero/impl/PendingStateTest.java +++ b/modAionImpl/test/org/aion/zero/impl/PendingStateTest.java @@ -6,6 +6,7 @@ import org.aion.base.type.AionAddress; import org.aion.crypto.ECKey; import org.aion.mcf.blockchain.TxResponse; +import org.aion.vm.api.interfaces.Address; import org.aion.zero.impl.config.CfgAion; import org.aion.zero.types.AionTransaction; import org.junit.Test; @@ -26,7 +27,7 @@ public void TestAddPendingTransactionSuccess() { AionHub hub = AionHub.createForTesting(CfgAion.inst(), bc, bc.getRepository()); - AionAddress to = new AionAddress(bundle.privateKeys.get(0).getAddress()); + Address to = new AionAddress(bundle.privateKeys.get(0).getAddress()); ECKey signer = bundle.privateKeys.get(1); // Successful transaction @@ -59,7 +60,7 @@ public void TestAddPendingTransactionInvalidNrgPrice() { AionHub hub = AionHub.createForTesting(CfgAion.inst(), bc, bc.getRepository()); - AionAddress to = new AionAddress(bundle.privateKeys.get(0).getAddress()); + Address to = new AionAddress(bundle.privateKeys.get(0).getAddress()); ECKey signer = bundle.privateKeys.get(1); // Invalid Nrg Price transaction diff --git a/modAionImpl/test/org/aion/zero/impl/blockchain/AionTxExecSummaryTest.java b/modAionImpl/test/org/aion/zero/impl/blockchain/AionTxExecSummaryTest.java index 9a85f66906..96496f86ae 100644 --- a/modAionImpl/test/org/aion/zero/impl/blockchain/AionTxExecSummaryTest.java +++ b/modAionImpl/test/org/aion/zero/impl/blockchain/AionTxExecSummaryTest.java @@ -7,6 +7,7 @@ import org.aion.base.type.AionAddress; import org.aion.crypto.HashUtil; import org.aion.mcf.vm.types.Bloom; +import org.aion.vm.api.interfaces.Address; import org.aion.zero.types.AionTransaction; import org.aion.zero.types.AionTxExecSummary; import org.aion.zero.types.AionTxReceipt; @@ -15,7 +16,7 @@ /** Test cases for AionTxExecSummary */ public class AionTxExecSummaryTest { - private AionAddress defaultAddress = + private Address defaultAddress = AionAddress.wrap("CAFECAFECAFECAFECAFECAFECAFECAFECAFECAFECAFECAFECAFECAFECAFECAFE"); @Test diff --git a/modAionImpl/test/org/aion/zero/impl/core/BloomFilterTest.java b/modAionImpl/test/org/aion/zero/impl/core/BloomFilterTest.java index 7f72897230..af5d1b1b13 100644 --- a/modAionImpl/test/org/aion/zero/impl/core/BloomFilterTest.java +++ b/modAionImpl/test/org/aion/zero/impl/core/BloomFilterTest.java @@ -6,6 +6,7 @@ import org.aion.base.type.AionAddress; import org.aion.crypto.HashUtil; import org.aion.mcf.vm.types.Bloom; +import org.aion.vm.api.interfaces.Address; import org.junit.Test; /** @@ -24,7 +25,7 @@ public void testSimpleAddSearchBloom() { @Test public void testContainsAddress() { - AionAddress addr = + Address addr = new AionAddress("FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF"); Bloom bloom = BloomFilter.create(addr.toBytes()); assertThat(BloomFilter.containsAddress(bloom, addr)).isTrue(); @@ -47,7 +48,7 @@ public void testContainsEvent2() { @Test public void testCompositeBloomFiltering() { - AionAddress addr = + Address addr = new AionAddress("BEEBEEBEEBEEBEEBEEBEEBEEBEEBEEBEEBEEBEEBEEBEEBEEBEEBEEBEEBEEFFFF"); byte[] someEvent = HashUtil.h256(BigInteger.ONE.toByteArray()); byte[] anotherEvent = HashUtil.h256(BigInteger.TWO.toByteArray()); diff --git a/modAionImpl/test/org/aion/zero/impl/db/AionRepositoryImplTest.java b/modAionImpl/test/org/aion/zero/impl/db/AionRepositoryImplTest.java index 741624a08a..911b0092b5 100644 --- a/modAionImpl/test/org/aion/zero/impl/db/AionRepositoryImplTest.java +++ b/modAionImpl/test/org/aion/zero/impl/db/AionRepositoryImplTest.java @@ -21,6 +21,7 @@ import org.aion.mcf.core.AccountState; import org.aion.mcf.db.IBlockStoreBase; import org.aion.mcf.vm.types.DataWord; +import org.aion.vm.api.interfaces.Address; import org.aion.zero.db.AionContractDetailsImpl; import org.junit.FixMethodOrder; import org.junit.Test; @@ -67,7 +68,7 @@ public void testAccountStateUpdate() { AionRepositoryImpl repository = AionRepositoryImpl.createForTesting(repoConfig); byte[] originalRoot = repository.getRoot(); - AionAddress defaultAccount = AionAddress.wrap(ByteUtil.hexStringToBytes(value1)); + Address defaultAccount = AionAddress.wrap(ByteUtil.hexStringToBytes(value1)); IRepositoryCache track = repository.startTracking(); track.addBalance(defaultAccount, BigInteger.valueOf(1)); @@ -85,7 +86,7 @@ public void testAccountAddCodeStorage() { AionRepositoryImpl repository = AionRepositoryImpl.createForTesting(repoConfig); IRepositoryCache track = repository.startTracking(); - AionAddress defaultAccount = AionAddress.wrap(ByteUtil.hexStringToBytes(value1)); + Address defaultAccount = AionAddress.wrap(ByteUtil.hexStringToBytes(value1)); track.addBalance(defaultAccount, BigInteger.valueOf(1)); byte[] originalRoot = repository.getRoot(); @@ -106,7 +107,7 @@ public void testAccountStateUpdateStorageRow() { AionRepositoryImpl repository = AionRepositoryImpl.createForTesting(repoConfig); IRepositoryCache track = repository.startTracking(); - AionAddress defaultAccount = AionAddress.wrap(ByteUtil.hexStringToBytes(value1)); + Address defaultAccount = AionAddress.wrap(ByteUtil.hexStringToBytes(value1)); track.addBalance(defaultAccount, BigInteger.valueOf(1)); // Consider the original root the one after an account has been added @@ -135,7 +136,7 @@ public void testAccountStateUpdateStorageRowFlush() { AionRepositoryImpl repository = AionRepositoryImpl.createForTesting(repoConfig); IRepositoryCache track = repository.startTracking(); - AionAddress defaultAccount = AionAddress.wrap(ByteUtil.hexStringToBytes(value1)); + Address defaultAccount = AionAddress.wrap(ByteUtil.hexStringToBytes(value1)); track.addBalance(defaultAccount, BigInteger.valueOf(1)); // Consider the original root the one after an account has been added @@ -173,7 +174,7 @@ public void testRepoTrackUpdateStorageRow() { final AionRepositoryImpl repository = AionRepositoryImpl.createForTesting(repoConfig); final IRepositoryCache> repoTrack = repository.startTracking(); - final AionAddress defaultAccount = AionAddress.wrap(ByteUtil.hexStringToBytes(value1)); + final Address defaultAccount = AionAddress.wrap(ByteUtil.hexStringToBytes(value1)); final byte[] key = HashUtil.blake128("hello".getBytes()); final byte[] value = HashUtil.blake128("world".getBytes()); @@ -200,8 +201,8 @@ public void testRepoTrackUpdateStorageRow() { @Test public void testSyncToPreviousRootNoFlush() { - final AionAddress FIRST_ACC = AionAddress.wrap(value2); - final AionAddress SECOND_ACC = AionAddress.wrap(value3); + final Address FIRST_ACC = AionAddress.wrap(value2); + final Address SECOND_ACC = AionAddress.wrap(value3); final AionRepositoryImpl repository = AionRepositoryImpl.createForTesting(repoConfig); byte[] originalRoot = repository.getRoot(); @@ -246,7 +247,7 @@ public void testSyncToPreviousRootNoFlush() { @Test public void testSyncToPreviousRootWithFlush() { - final AionAddress FIRST_ACC = AionAddress.wrap(value2); + final Address FIRST_ACC = AionAddress.wrap(value2); AionRepositoryImpl repository = AionRepositoryImpl.createForTesting(repoConfig); byte[] originalRoot = repository.getRoot(); @@ -284,9 +285,8 @@ public void testSyncToPreviousRootWithFlush() { public void test17NodePreviousRootTest() { // not that it matters since things are going to be hashed, but at least // the root node should point to a node that contains references to both - final AionAddress DOG_ACC = AionAddress.wrap("00000000000000000000000000000dog".getBytes()); - final AionAddress DOGE_ACC = - AionAddress.wrap("0000000000000000000000000000doge".getBytes()); + final Address DOG_ACC = AionAddress.wrap("00000000000000000000000000000dog".getBytes()); + final Address DOGE_ACC = AionAddress.wrap("0000000000000000000000000000doge".getBytes()); AionRepositoryImpl repository = AionRepositoryImpl.createForTesting(repoConfig); IRepositoryCache track = repository.startTracking(); @@ -317,9 +317,9 @@ public void testGetSnapshotToRoot() { AionRepositoryImpl repository = AionRepositoryImpl.createForTesting(repoConfig); // make some changes to the repository - final AionAddress account1 = AionAddress.wrap(value1); - final AionAddress account2 = AionAddress.wrap(value2); - final AionAddress account3 = AionAddress.wrap(value3); + final Address account1 = AionAddress.wrap(value1); + final Address account2 = AionAddress.wrap(value2); + final Address account3 = AionAddress.wrap(value3); IRepositoryCache track = repository.startTracking(); track.addBalance(account1, BigInteger.ONE); track.addBalance(account2, BigInteger.TWO); diff --git a/modAionImpl/test/org/aion/zero/impl/vm/Benchmark.java b/modAionImpl/test/org/aion/zero/impl/vm/Benchmark.java index 3116a8765a..3028fba0b7 100644 --- a/modAionImpl/test/org/aion/zero/impl/vm/Benchmark.java +++ b/modAionImpl/test/org/aion/zero/impl/vm/Benchmark.java @@ -48,6 +48,7 @@ import org.aion.vm.BulkExecutor; import org.aion.vm.ExecutionBatch; import org.aion.vm.PostExecutionWork; +import org.aion.vm.api.interfaces.Address; import org.aion.zero.impl.db.AionRepositoryImpl; import org.aion.zero.impl.types.AionBlock; import org.aion.zero.impl.vm.contracts.ContractUtils; @@ -64,8 +65,8 @@ public class Benchmark { private static IRepositoryCache> repo = db.startTracking(); private static ECKey key; - private static AionAddress owner; - private static AionAddress contract; + private static Address owner; + private static Address contract; private static List recipients = new ArrayList<>(); @@ -91,8 +92,8 @@ private static void prepare() throws IOException { byte[] deployer = ContractUtils.getContractDeployer("BenchmarkERC20.sol", "FixedSupplyToken"); byte[] nonce = DataWord.ZERO.getData(); - AionAddress from = owner; - AionAddress to = null; + Address from = owner; + Address to = null; byte[] value = DataWord.ZERO.getData(); long nrg = 1_000_000L; long nrgPrice = 1L; @@ -131,8 +132,8 @@ private static List signTransactions(int num) { // transfer token to random people byte[] nonce = new DataWord(ownerNonce + i).getData(); - AionAddress from = owner; - AionAddress to = contract; + Address from = owner; + Address to = contract; byte[] value = DataWord.ZERO.getData(); byte[] data = ByteUtil.merge( @@ -220,8 +221,8 @@ private static void verifyState(int num) { for (int i = 0; i < recipients.size(); i++) { byte[] nonce = new DataWord(ownerNonce + i).getData(); - AionAddress from = owner; - AionAddress to = contract; + Address from = owner; + Address to = contract; byte[] value = DataWord.ZERO.getData(); byte[] data = ByteUtil.merge( @@ -268,7 +269,7 @@ public static void main(String args[]) throws IOException { private static AionBlock createDummyBlock() { byte[] parentHash = new byte[32]; - byte[] coinbase = RandomUtils.nextBytes(AionAddress.SIZE); + byte[] coinbase = RandomUtils.nextBytes(Address.SIZE); byte[] logsBloom = new byte[0]; byte[] difficulty = new DataWord(0x1000000L).getData(); long number = 1; diff --git a/modAionImpl/test/org/aion/zero/impl/vm/ContractIntegTest.java b/modAionImpl/test/org/aion/zero/impl/vm/ContractIntegTest.java index 5dd5024098..14e54cf90f 100644 --- a/modAionImpl/test/org/aion/zero/impl/vm/ContractIntegTest.java +++ b/modAionImpl/test/org/aion/zero/impl/vm/ContractIntegTest.java @@ -47,6 +47,7 @@ import org.aion.vm.BulkExecutor; import org.aion.vm.ExecutionBatch; import org.aion.vm.PostExecutionWork; +import org.aion.vm.api.interfaces.Address; import org.aion.vm.api.interfaces.ResultCode; import org.aion.zero.impl.BlockContext; import org.aion.zero.impl.StandaloneBlockchain; @@ -71,7 +72,7 @@ public class ContractIntegTest { private static final Logger LOGGER_VM = AionLoggerFactory.getLogger(LogEnum.VM.toString()); private StandaloneBlockchain blockchain; private ECKey deployerKey; - private AionAddress deployer; + private Address deployer; private BigInteger deployerBalance, deployerNonce; @Before @@ -132,7 +133,7 @@ public void testEmptyContract() throws IOException { assertEquals("", summary.getReceipt().getError()); // "" == SUCCESS assertEquals(tx.getNrgConsume(), summary.getReceipt().getEnergyUsed()); - AionAddress contract = tx.getContractAddress(); + Address contract = tx.getContractAddress(); checkStateOfNewContract( repo, contractName, contract, summary.getResult(), FastVmResultCode.SUCCESS, value); nonce = nonce.add(BigInteger.ONE); @@ -165,7 +166,7 @@ public void testContractDeployCodeIsEmpty() { assertEquals("", summary.getReceipt().getError()); // "" == SUCCESS assertEquals(tx.getNrgConsume(), summary.getNrgUsed().longValue()); - AionAddress contract = tx.getContractAddress(); + Address contract = tx.getContractAddress(); assertArrayEquals(new byte[0], summary.getResult()); assertArrayEquals(new byte[0], repo.getCode(contract)); assertEquals(BigInteger.ZERO, repo.getBalance(contract)); @@ -205,7 +206,7 @@ public void testContractDeployCodeIsNonsensical() { assertEquals(tx.getNrgConsume(), summary.getNrgUsed().longValue()); assertEquals(nrg, tx.getNrgConsume()); - AionAddress contract = tx.getContractAddress(); + Address contract = tx.getContractAddress(); assertArrayEquals(new byte[0], summary.getResult()); assertArrayEquals(new byte[0], repo.getCode(contract)); assertEquals(BigInteger.ZERO, repo.getBalance(contract)); @@ -245,7 +246,7 @@ public void testTransferValueToNonPayableConstructor() throws IOException { assertEquals(tx.getNrgConsume(), summary.getNrgUsed().longValue()); assertNotEquals(nrg, tx.getNrgConsume()); // all energy is not used up. - AionAddress contract = tx.getContractAddress(); + Address contract = tx.getContractAddress(); checkStateOfNewContract( repo, contractName, @@ -286,7 +287,7 @@ public void testTransferValueToPayableConstructor() throws IOException { assertEquals(tx.getNrgConsume(), summary.getNrgUsed().longValue()); assertNotEquals(nrg, tx.getNrgConsume()); // all energy is not used up. - AionAddress contract = tx.getContractAddress(); + Address contract = tx.getContractAddress(); checkStateOfNewContract( repo, contractName, contract, summary.getResult(), FastVmResultCode.SUCCESS, value); nonce = nonce.add(BigInteger.ONE); @@ -322,7 +323,7 @@ public void testTransferValueToPayableConstructorInsufficientFunds() throws IOEx assertEquals(0, tx.getNrgConsume()); // assertEquals(0, summary.getNrgUsed().longValue()); //FIXME: confirm above - AionAddress contract = tx.getContractAddress(); + Address contract = tx.getContractAddress(); checkStateOfNewContract( repo, contractName, @@ -350,7 +351,7 @@ public void testConstructorIsCalledOnCodeDeployment() throws IOException { IRepositoryCache repo = blockchain.getRepository().startTracking(); nonce = nonce.add(BigInteger.ONE); - AionAddress contract = + Address contract = deployContract(repo, tx, contractName, null, value, nrg, nrgPrice, nonce); // Now call the contract and check that the constructor message was set. @@ -392,7 +393,7 @@ public void testCallFunction() throws IOException { nonce.toByteArray(), null, value.toByteArray(), deployCode, nrg, nrgPrice); IRepositoryCache repo = blockchain.getRepository().startTracking(); nonce = nonce.add(BigInteger.ONE); - AionAddress contract = + Address contract = deployContract(repo, tx, contractName, null, value, nrg, nrgPrice, nonce); // ---------- This command will perform addition. ---------- @@ -467,7 +468,7 @@ public void testOverWithdrawFromContract() throws IOException { nonce.toByteArray(), null, value.toByteArray(), deployCode, nrg, nrgPrice); IRepositoryCache repo = blockchain.getRepository().startTracking(); nonce = nonce.add(BigInteger.ONE); - AionAddress contract = + Address contract = deployContract(repo, tx, contractName, null, value, nrg, nrgPrice, nonce); BigInteger deployerBalance = repo.getBalance(deployer); @@ -516,7 +517,7 @@ public void testWithdrawFromContract() throws IOException { nonce.toByteArray(), null, value.toByteArray(), deployCode, nrg, nrgPrice); IRepositoryCache repo = blockchain.getRepository().startTracking(); nonce = nonce.add(BigInteger.ONE); - AionAddress contract = + Address contract = deployContract(repo, tx, contractName, null, value, nrg, nrgPrice, nonce); BigInteger deployerBalance = repo.getBalance(deployer); @@ -562,13 +563,13 @@ public void testSendContractFundsToOtherAddress() throws IOException { nonce.toByteArray(), null, value.toByteArray(), deployCode, nrg, nrgPrice); IRepositoryCache repo = blockchain.getRepository().startTracking(); nonce = nonce.add(BigInteger.ONE); - AionAddress contract = + Address contract = deployContract(repo, tx, contractName, null, value, nrg, nrgPrice, nonce); BigInteger deployerBalance = repo.getBalance(deployer); // Create a new account to be our fund recipient. - AionAddress recipient = new AionAddress(RandomUtils.nextBytes(AionAddress.SIZE)); + Address recipient = new AionAddress(RandomUtils.nextBytes(Address.SIZE)); repo.createAccount(recipient); // Contract has 2^13 coins, let's withdraw them. @@ -615,13 +616,13 @@ public void testSendContractFundsToNonexistentAddress() throws IOException { nonce.toByteArray(), null, value.toByteArray(), deployCode, nrg, nrgPrice); IRepositoryCache repo = blockchain.getRepository().startTracking(); nonce = nonce.add(BigInteger.ONE); - AionAddress contract = + Address contract = deployContract(repo, tx, contractName, null, value, nrg, nrgPrice, nonce); BigInteger deployerBalance = repo.getBalance(deployer); // Create a new account to be our fund recipient. - AionAddress recipient = new AionAddress(RandomUtils.nextBytes(AionAddress.SIZE)); + Address recipient = new AionAddress(RandomUtils.nextBytes(Address.SIZE)); // Contract has 2^13 coins, let's withdraw them. byte[] input = ByteUtil.merge(Hex.decode("8c50612c"), recipient.toBytes()); @@ -668,7 +669,7 @@ public void testCallContractViaAnotherContract() throws IOException { nonce.toByteArray(), null, value.toByteArray(), deployCode, nrg, nrgPrice); IRepositoryCache repo = blockchain.getRepository().startTracking(); nonce = nonce.add(BigInteger.ONE); - AionAddress multiFeatureContract = + Address multiFeatureContract = deployContract(repo, tx, contractName, null, value, nrg, nrgPrice, nonce); deployerBalance = repo.getBalance(deployer); @@ -682,9 +683,9 @@ public void testCallContractViaAnotherContract() throws IOException { new AionTransaction( nonce.toByteArray(), null, value.toByteArray(), deployCode, nrg, nrgPrice); nonce = nonce.add(BigInteger.ONE); - AionAddress callerContract = + Address callerContract = deployContract(repo, tx, contractName, null, value, nrg, nrgPrice, nonce); - AionAddress recipient = new AionAddress(RandomUtils.nextBytes(AionAddress.SIZE)); + Address recipient = new AionAddress(RandomUtils.nextBytes(Address.SIZE)); deployerBalance = repo.getBalance(deployer); deployerNonce = repo.getNonce(deployer); @@ -762,7 +763,7 @@ public void testRecursiveStackoverflow() throws IOException { nonce.toByteArray(), null, value.toByteArray(), deployCode, nrg, nrgPrice); IRepositoryCache repo = blockchain.getRepository().startTracking(); nonce = nonce.add(BigInteger.ONE); - AionAddress contract = + Address contract = deployContract(repo, tx, contractName, null, value, nrg, nrgPrice, nonce); deployerBalance = repo.getBalance(deployer); @@ -892,9 +893,9 @@ public void testRedeployContractAtExistentContractAddress() throws IOException { // Mock up the repo so that the contract address already exists. IRepositoryCache repo = mock(IRepositoryCache.class); - when(repo.hasAccountState(Mockito.any(AionAddress.class))).thenReturn(true); - when(repo.getNonce(Mockito.any(AionAddress.class))).thenReturn(nonce); - when(repo.getBalance(Mockito.any(AionAddress.class))).thenReturn(Builder.DEFAULT_BALANCE); + when(repo.hasAccountState(Mockito.any(Address.class))).thenReturn(true); + when(repo.getNonce(Mockito.any(Address.class))).thenReturn(nonce); + when(repo.getBalance(Mockito.any(Address.class))).thenReturn(Builder.DEFAULT_BALANCE); when(repo.startTracking()).thenReturn(repo); tx.sign(deployerKey); @@ -930,7 +931,7 @@ public void testCallPrecompiledViaSmartContract() throws IOException { // nrgPrice); // IRepositoryCache repo = blockchain.getRepository().startTracking(); // nonce = nonce.add(BigInteger.ONE); - // AionAddress contract = + // Address contract = // deployContract(repo, tx, contractName, null, value, nrg, nrgPrice, nonce); // // deployerBalance = repo.getBalance(deployer); @@ -986,7 +987,7 @@ public void testCallPrecompiledViaSmartContract() throws IOException { * Deploys a contract named contractName and checks the state of the deployed contract and the * contract deployer and returns the address of the contract once finished. */ - private AionAddress deployContract( + private Address deployContract( IRepositoryCache repo, AionTransaction tx, String contractName, @@ -1013,7 +1014,7 @@ private AionAddress deployContract( assertEquals(tx.getNrgConsume(), summary.getNrgUsed().longValue()); assertNotEquals(nrg, tx.getNrgConsume()); - AionAddress contract = tx.getContractAddress(); + Address contract = tx.getContractAddress(); if (contractFilename == null) { checkStateOfNewContract( repo, @@ -1061,7 +1062,7 @@ private byte[] getBodyCode(String contractName) throws IOException { private void checkStateOfNewContract( IRepositoryCache repo, String contractName, - AionAddress contractAddr, + Address contractAddr, byte[] output, ResultCode result, BigInteger value) @@ -1088,7 +1089,7 @@ private void checkStateOfNewContract( IRepositoryCache repo, String contractName, String contractFilename, - AionAddress contractAddr, + Address contractAddr, byte[] output, FastVmResultCode result, BigInteger value) diff --git a/modAionImpl/test/org/aion/zero/impl/vm/InternalTransactionTest.java b/modAionImpl/test/org/aion/zero/impl/vm/InternalTransactionTest.java index ed03b14eed..50861adee3 100644 --- a/modAionImpl/test/org/aion/zero/impl/vm/InternalTransactionTest.java +++ b/modAionImpl/test/org/aion/zero/impl/vm/InternalTransactionTest.java @@ -30,7 +30,6 @@ import java.math.BigInteger; import java.util.Collections; import java.util.List; -import org.aion.base.type.AionAddress; import org.aion.base.util.ByteUtil; import org.aion.crypto.ECKey; import org.aion.log.AionLoggerFactory; @@ -40,6 +39,7 @@ import org.aion.vm.BulkExecutor; import org.aion.vm.ExecutionBatch; import org.aion.vm.PostExecutionWork; +import org.aion.vm.api.interfaces.Address; import org.aion.vm.api.interfaces.InternalTransactionInterface; import org.aion.zero.impl.BlockContext; import org.aion.zero.impl.StandaloneBlockchain; @@ -126,9 +126,9 @@ public void testLogs() throws InterruptedException { ImportResult result = bc.tryToConnect(context.block); assertThat(result).isEqualTo(ImportResult.IMPORTED_BEST); - AionAddress addressA = tx1.getContractAddress(); + Address addressA = tx1.getContractAddress(); System.out.println("contract A = " + addressA); - AionAddress addressB = tx2.getContractAddress(); + Address addressB = tx2.getContractAddress(); System.out.println("contract B = " + addressB); Thread.sleep(1000); @@ -251,7 +251,7 @@ public void testRecursiveCall() throws InterruptedException { ImportResult result = bc.tryToConnect(context.block); assertThat(result).isEqualTo(ImportResult.IMPORTED_BEST); - AionAddress addressA = tx1.getContractAddress(); + Address addressA = tx1.getContractAddress(); System.out.println("contract A = " + addressA); Thread.sleep(1000); diff --git a/modAionImpl/test/org/aion/zero/impl/vm/OldTxExecutorTest.java b/modAionImpl/test/org/aion/zero/impl/vm/OldTxExecutorTest.java index 7925a26697..15f3f0e2f4 100644 --- a/modAionImpl/test/org/aion/zero/impl/vm/OldTxExecutorTest.java +++ b/modAionImpl/test/org/aion/zero/impl/vm/OldTxExecutorTest.java @@ -45,6 +45,7 @@ import org.aion.vm.BulkExecutor; import org.aion.vm.ExecutionBatch; import org.aion.vm.PostExecutionWork; +import org.aion.vm.api.interfaces.Address; import org.aion.zero.impl.StandaloneBlockchain; import org.aion.zero.impl.db.AionRepositoryImpl; import org.aion.zero.impl.types.AionBlock; @@ -92,11 +93,11 @@ public void testCallTransaction() throws IOException { String contract = deployer.substring(deployer.indexOf("60506040", 1)); // contract byte[] txNonce = DataWord.ZERO.getData(); - AionAddress from = + Address from = AionAddress.wrap( Hex.decode( "1111111111111111111111111111111111111111111111111111111111111111")); - AionAddress to = + Address to = AionAddress.wrap( Hex.decode( "2222222222222222222222222222222222222222222222222222222222222222")); @@ -143,11 +144,11 @@ public void testCreateTransaction() throws IOException { System.out.println(deployer); byte[] txNonce = DataWord.ZERO.getData(); - AionAddress from = + Address from = AionAddress.wrap( Hex.decode( "1111111111111111111111111111111111111111111111111111111111111111")); - AionAddress to = AionAddress.EMPTY_ADDRESS(); + Address to = AionAddress.EMPTY_ADDRESS(); byte[] value = DataWord.ZERO.getData(); byte[] data = Hex.decode(deployer); long nrg = 500_000L; @@ -189,11 +190,11 @@ public void testPerformance() throws IOException { String contract = deployer.substring(deployer.indexOf("60506040", 1)); // contract byte[] txNonce = DataWord.ZERO.getData(); - AionAddress from = + Address from = AionAddress.wrap( Hex.decode( "1111111111111111111111111111111111111111111111111111111111111111")); - AionAddress to = + Address to = AionAddress.wrap( Hex.decode( "2222222222222222222222222222222222222222222222222222222222222222")); @@ -235,11 +236,11 @@ public void testPerformance() throws IOException { @Test public void testBasicTransactionCost() { byte[] txNonce = DataWord.ZERO.getData(); - AionAddress from = + Address from = AionAddress.wrap( Hex.decode( "1111111111111111111111111111111111111111111111111111111111111111")); - AionAddress to = + Address to = AionAddress.wrap( Hex.decode( "2222222222222222222222222222222222222222222222222222222222222222")); @@ -274,7 +275,7 @@ public void testBasicTransactionCost() { private static AionBlock createDummyBlock() { byte[] parentHash = new byte[32]; - byte[] coinbase = RandomUtils.nextBytes(AionAddress.SIZE); + byte[] coinbase = RandomUtils.nextBytes(Address.SIZE); byte[] logsBloom = new byte[0]; byte[] difficulty = new DataWord(0x1000000L).getData(); long number = 1; diff --git a/modAionImpl/test/org/aion/zero/impl/vm/OpcodeIntegTest.java b/modAionImpl/test/org/aion/zero/impl/vm/OpcodeIntegTest.java index 8cef4c83e3..26f22e2be9 100644 --- a/modAionImpl/test/org/aion/zero/impl/vm/OpcodeIntegTest.java +++ b/modAionImpl/test/org/aion/zero/impl/vm/OpcodeIntegTest.java @@ -44,6 +44,7 @@ import org.aion.vm.BulkExecutor; import org.aion.vm.ExecutionBatch; import org.aion.vm.PostExecutionWork; +import org.aion.vm.api.interfaces.Address; import org.aion.vm.api.interfaces.IExecutionLog; import org.aion.vm.api.interfaces.InternalTransactionInterface; import org.aion.zero.impl.BlockContext; @@ -63,7 +64,7 @@ public class OpcodeIntegTest { private static final Logger LOGGER_VM = AionLoggerFactory.getLogger(LogEnum.VM.toString()); private StandaloneBlockchain blockchain; private ECKey deployerKey; - private AionAddress deployer; + private Address deployer; private BigInteger deployerBalance; @Before @@ -92,7 +93,7 @@ public void tearDown() { @Test public void testNoRevert() throws IOException { IRepositoryCache repo = blockchain.getRepository().startTracking(); - AionAddress D = deployContract(repo, "F", "F.sol", BigInteger.ZERO); + Address D = deployContract(repo, "F", "F.sol", BigInteger.ZERO); long nrg = 1_000_000; long nrgPrice = 1; BigInteger nonce = BigInteger.ONE; @@ -137,7 +138,7 @@ public void testNoRevert() throws IOException { @Test public void testRevertAtBottomLevel() throws IOException { IRepositoryCache repo = blockchain.getRepository().startTracking(); - AionAddress D = deployContract(repo, "F", "F.sol", BigInteger.ZERO); + Address D = deployContract(repo, "F", "F.sol", BigInteger.ZERO); long nrg = 1_000_000; long nrgPrice = 1; BigInteger nonce = BigInteger.ONE; @@ -178,7 +179,7 @@ public void testRevertAtBottomLevel() throws IOException { @Test public void testRevertAtMidLevel() throws IOException { IRepositoryCache repo = blockchain.getRepository().startTracking(); - AionAddress D = deployContract(repo, "F", "F.sol", BigInteger.ZERO); + Address D = deployContract(repo, "F", "F.sol", BigInteger.ZERO); long nrg = 1_000_000; long nrgPrice = 1; BigInteger nonce = BigInteger.ONE; @@ -222,8 +223,8 @@ public void testRevertAtMidLevel() throws IOException { public void testCallcodeStorage() throws IOException { IRepositoryCache repo = blockchain.getRepository().startTracking(); BigInteger n = new BigInteger("7638523"); - AionAddress D = deployContract(repo, "D", "D.sol", BigInteger.ZERO); - AionAddress E = deployContract(repo, "E", "D.sol", BigInteger.ZERO); + Address D = deployContract(repo, "D", "D.sol", BigInteger.ZERO); + Address E = deployContract(repo, "E", "D.sol", BigInteger.ZERO); // Deployer calls contract D which performs CALLCODE to call contract E. We expect that the // storage in contract D is modified by the code that is called in contract E. @@ -301,8 +302,8 @@ public void testCallcodeStorage() throws IOException { @Test public void testCallcodeActors() throws IOException { IRepositoryCache repo = blockchain.getRepository().startTracking(); - AionAddress D = deployContract(repo, "D", "D.sol", BigInteger.ZERO); - AionAddress E = deployContract(repo, "E", "D.sol", BigInteger.ZERO); + Address D = deployContract(repo, "D", "D.sol", BigInteger.ZERO); + Address E = deployContract(repo, "E", "D.sol", BigInteger.ZERO); // Deployer calls contract D which performs CALLCODE to call contract E. From the // perspective @@ -343,8 +344,8 @@ public void testCallcodeActors() throws IOException { @Test public void testCallcodeValueTransfer() throws IOException { IRepositoryCache repo = blockchain.getRepository().startTracking(); - AionAddress D = deployContract(repo, "D", "D.sol", BigInteger.ZERO); - AionAddress E = deployContract(repo, "E", "D.sol", BigInteger.ZERO); + Address D = deployContract(repo, "D", "D.sol", BigInteger.ZERO); + Address E = deployContract(repo, "E", "D.sol", BigInteger.ZERO); BigInteger balanceDeployer = repo.getBalance(deployer); BigInteger balanceD = repo.getBalance(D); @@ -386,8 +387,8 @@ public void testCallcodeValueTransfer() throws IOException { @Test public void testDelegateCallStorage() throws IOException { IRepositoryCache repo = blockchain.getRepository().startTracking(); - AionAddress D = deployContract(repo, "D", "D.sol", BigInteger.ZERO); - AionAddress E = deployContract(repo, "E", "D.sol", BigInteger.ZERO); + Address D = deployContract(repo, "D", "D.sol", BigInteger.ZERO); + Address E = deployContract(repo, "E", "D.sol", BigInteger.ZERO); BigInteger n = new BigInteger("23786523"); // Deployer calls contract D which performs DELEGATECALL to call contract E. @@ -461,8 +462,8 @@ public void testDelegateCallStorage() throws IOException { @Test public void testDelegateCallActors() throws IOException { IRepositoryCache repo = blockchain.getRepository().startTracking(); - AionAddress D = deployContract(repo, "D", "D.sol", BigInteger.ZERO); - AionAddress E = deployContract(repo, "E", "D.sol", BigInteger.ZERO); + Address D = deployContract(repo, "D", "D.sol", BigInteger.ZERO); + Address E = deployContract(repo, "E", "D.sol", BigInteger.ZERO); BigInteger n = new BigInteger("23786523"); // Deployer calls contract D which performs DELEGATECALL to call contract E. @@ -500,8 +501,8 @@ public void testDelegateCallActors() throws IOException { @Test public void testDelegateCallValueTransfer() throws IOException { IRepositoryCache repo = blockchain.getRepository().startTracking(); - AionAddress D = deployContract(repo, "D", "D.sol", BigInteger.ZERO); - AionAddress E = deployContract(repo, "E", "D.sol", BigInteger.ZERO); + Address D = deployContract(repo, "D", "D.sol", BigInteger.ZERO); + Address E = deployContract(repo, "E", "D.sol", BigInteger.ZERO); BigInteger n = new BigInteger("23786523"); BigInteger balanceDeployer = repo.getBalance(deployer); @@ -545,8 +546,8 @@ public void testDelegateCallValueTransfer() throws IOException { @Test public void testOpcodesActors() throws IOException { IRepositoryCache repo = blockchain.getRepository().startTracking(); - AionAddress callerContract = deployContract(repo, "Caller", "Opcodes.sol", BigInteger.ZERO); - AionAddress calleeContract = deployContract(repo, "Callee", "Opcodes.sol", BigInteger.ZERO); + Address callerContract = deployContract(repo, "Caller", "Opcodes.sol", BigInteger.ZERO); + Address calleeContract = deployContract(repo, "Callee", "Opcodes.sol", BigInteger.ZERO); System.err.println("Deployer: " + deployer); System.err.println("Caller: " + callerContract); @@ -593,10 +594,10 @@ public void testOpcodesActors() throws IOException { public void testSuicideRecipientExists() throws IOException { IRepositoryCache repo = blockchain.getRepository().startTracking(); BigInteger balance = new BigInteger("32522224"); - AionAddress recipient = new AionAddress(RandomUtils.nextBytes(AionAddress.SIZE)); + Address recipient = new AionAddress(RandomUtils.nextBytes(Address.SIZE)); repo.createAccount(recipient); - AionAddress contract = deployContract(repo, "Suicide", "Suicide.sol", BigInteger.ZERO); + Address contract = deployContract(repo, "Suicide", "Suicide.sol", BigInteger.ZERO); repo.addBalance(contract, balance); BigInteger balanceDeployer = repo.getBalance(deployer); @@ -640,9 +641,9 @@ public void testSuicideRecipientExists() throws IOException { public void testSuicideRecipientNewlyCreated() throws IOException { IRepositoryCache repo = blockchain.getRepository().startTracking(); BigInteger balance = new BigInteger("32522224"); - AionAddress recipient = new AionAddress(RandomUtils.nextBytes(AionAddress.SIZE)); + Address recipient = new AionAddress(RandomUtils.nextBytes(Address.SIZE)); - AionAddress contract = deployContract(repo, "Suicide", "Suicide.sol", BigInteger.ZERO); + Address contract = deployContract(repo, "Suicide", "Suicide.sol", BigInteger.ZERO); repo.addBalance(contract, balance); BigInteger balanceDeployer = repo.getBalance(deployer); @@ -689,7 +690,7 @@ public void testSuicideRecipientNewlyCreated() throws IOException { /** * Deploys the contract named contractName in the file named contractFilename with value value. */ - private AionAddress deployContract( + private Address deployContract( IRepositoryCache repo, String contractName, String contractFilename, BigInteger value) throws IOException { @@ -700,7 +701,7 @@ private AionAddress deployContract( AionTransaction tx = new AionTransaction( nonce.toByteArray(), null, value.toByteArray(), deployCode, nrg, nrgPrice); - AionAddress contract = + Address contract = deployContract( repo, tx, contractName, contractFilename, value, nrg, nrgPrice, nonce); deployerBalance = repo.getBalance(deployer); @@ -713,7 +714,7 @@ private AionAddress deployContract( * *

Returns the address of the newly deployed contract. */ - private AionAddress deployContract( + private Address deployContract( IRepositoryCache repo, AionTransaction tx, String contractName, @@ -739,7 +740,7 @@ private AionAddress deployContract( assertEquals(tx.getNrgConsume(), summary.getNrgUsed().longValue()); assertNotEquals(nrg, tx.getNrgConsume()); - AionAddress contract = tx.getContractAddress(); + Address contract = tx.getContractAddress(); checkStateOfNewContract(repo, contractName, contractFilename, contract, value); checkStateOfDeployer( repo, @@ -760,7 +761,7 @@ private void checkStateOfNewContract( IRepositoryCache repo, String contractName, String contractFilename, - AionAddress contractAddr, + Address contractAddr, BigInteger valueTransferred) throws IOException { @@ -793,14 +794,12 @@ private void checkStateOfDeployer( * byte array consisting of the bytes of owner then caller then origin then finally 16 zero * bytes. */ - private void verifyLogData( - byte[] data, AionAddress owner, AionAddress caller, AionAddress origin) { - assertArrayEquals(Arrays.copyOfRange(data, 0, AionAddress.SIZE), owner.toBytes()); + private void verifyLogData(byte[] data, Address owner, Address caller, Address origin) { + assertArrayEquals(Arrays.copyOfRange(data, 0, Address.SIZE), owner.toBytes()); assertArrayEquals( - Arrays.copyOfRange(data, AionAddress.SIZE, AionAddress.SIZE * 2), caller.toBytes()); + Arrays.copyOfRange(data, Address.SIZE, Address.SIZE * 2), caller.toBytes()); assertArrayEquals( - Arrays.copyOfRange(data, AionAddress.SIZE * 2, AionAddress.SIZE * 3), - origin.toBytes()); + Arrays.copyOfRange(data, Address.SIZE * 2, Address.SIZE * 3), origin.toBytes()); assertArrayEquals( Arrays.copyOfRange(data, data.length - DataWord.BYTES, data.length), DataWord.ZERO.getData()); diff --git a/modAionImpl/test/org/aion/zero/impl/vm/SolidityTypeTest.java b/modAionImpl/test/org/aion/zero/impl/vm/SolidityTypeTest.java index e50df28e71..1628ee32ff 100644 --- a/modAionImpl/test/org/aion/zero/impl/vm/SolidityTypeTest.java +++ b/modAionImpl/test/org/aion/zero/impl/vm/SolidityTypeTest.java @@ -53,6 +53,7 @@ import org.aion.vm.BulkExecutor; import org.aion.vm.ExecutionBatch; import org.aion.vm.PostExecutionWork; +import org.aion.vm.api.interfaces.Address; import org.aion.zero.impl.StandaloneBlockchain; import org.aion.zero.impl.db.AionRepositoryImpl; import org.aion.zero.impl.types.AionBlock; @@ -87,11 +88,11 @@ public void tearDown() { private AionTransaction createTransaction(byte[] callData) { byte[] txNonce = DataWord.ZERO.getData(); - AionAddress from = + Address from = AionAddress.wrap( Hex.decode( "1111111111111111111111111111111111111111111111111111111111111111")); - AionAddress to = + Address to = AionAddress.wrap( Hex.decode( "2222222222222222222222222222222222222222222222222222222222222222")); @@ -414,7 +415,7 @@ private BulkExecutor getNewExecutor( private static AionBlock createDummyBlock() { byte[] parentHash = new byte[32]; - byte[] coinbase = RandomUtils.nextBytes(AionAddress.SIZE); + byte[] coinbase = RandomUtils.nextBytes(Address.SIZE); byte[] logsBloom = new byte[0]; byte[] difficulty = new DataWord(0x1000000L).getData(); long number = 1; diff --git a/modAionImpl/test/org/aion/zero/impl/vm/TransactionExecutorTest.java b/modAionImpl/test/org/aion/zero/impl/vm/TransactionExecutorTest.java index 085de425a6..43605db7b5 100644 --- a/modAionImpl/test/org/aion/zero/impl/vm/TransactionExecutorTest.java +++ b/modAionImpl/test/org/aion/zero/impl/vm/TransactionExecutorTest.java @@ -43,6 +43,7 @@ import org.aion.vm.BulkExecutor; import org.aion.vm.ExecutionBatch; import org.aion.vm.PostExecutionWork; +import org.aion.vm.api.interfaces.Address; import org.aion.zero.impl.BlockContext; import org.aion.zero.impl.StandaloneBlockchain; import org.aion.zero.impl.StandaloneBlockchain.Builder; @@ -62,7 +63,7 @@ public class TransactionExecutorTest { private static final String g_func = "e2179b8e"; private StandaloneBlockchain blockchain; private ECKey deployerKey; - private AionAddress deployer; + private Address deployer; @Before public void setup() { @@ -85,7 +86,7 @@ public void tearDown() { @Test public void testExecutor() throws IOException { - AionAddress to = getNewRecipient(true); + Address to = getNewRecipient(true); byte[] deployCode = ContractUtils.getContractDeployer("ByteArrayMap.sol", "ByteArrayMap"); long nrg = 1_000_000; long nrgPrice = 1; @@ -127,7 +128,7 @@ public void testExecutor() throws IOException { assertEquals("", summary.getReceipt().getError()); assertArrayEquals(body, summary.getResult()); - AionAddress contract = summary.getTransaction().getContractAddress(); + Address contract = summary.getTransaction().getContractAddress(); assertArrayEquals(body, repo.getCode(contract)); assertEquals(BigInteger.ZERO, repo.getBalance(contract)); assertEquals(BigInteger.ZERO, repo.getNonce(contract)); @@ -140,7 +141,7 @@ public void testExecutor() throws IOException { @Test public void testExecutorBlind() throws IOException { - AionAddress to = getNewRecipient(true); + Address to = getNewRecipient(true); byte[] deployCode = ContractUtils.getContractDeployer("ByteArrayMap.sol", "ByteArrayMap"); long nrg = 1_000_000; long nrgPrice = 1; @@ -168,7 +169,7 @@ public void testExecutorBlind() throws IOException { // transaction // fee plus the refund byte[] body = ContractUtils.getContractBody("ByteArrayMap.sol", "ByteArrayMap"); - AionAddress contract = tx.getContractAddress(); + Address contract = tx.getContractAddress(); assertArrayEquals(body, blockchain.getRepository().getCode(contract)); assertEquals(BigInteger.ZERO, blockchain.getRepository().getBalance(contract)); @@ -183,7 +184,7 @@ public void testExecutorBlind() throws IOException { @Test public void testDeployedCodeFunctionality() throws IOException { - AionAddress contract = deployByteArrayContract(); + Address contract = deployByteArrayContract(); byte[] callingCode = Hex.decode(f_func); BigInteger nonce = blockchain.getRepository().getNonce(deployer); AionTransaction tx = @@ -281,7 +282,7 @@ public void testDeployedCodeFunctionality() throws IOException { @Test public void testGfunction() throws IOException { - AionAddress contract = deployByteArrayContract(); + Address contract = deployByteArrayContract(); byte[] callingCode = Hex.decode(g_func); BigInteger nonce = blockchain.getRepository().getNonce(deployer); AionTransaction tx = @@ -322,8 +323,8 @@ public void testGfunction() throws IOException { // <-----------------------------------------HELPERS-------------------------------------------> - private AionAddress deployByteArrayContract() throws IOException { - AionAddress to = getNewRecipient(true); + private Address deployByteArrayContract() throws IOException { + Address to = getNewRecipient(true); byte[] deployCode = ContractUtils.getContractDeployer("ByteArrayMap.sol", "ByteArrayMap"); long nrg = 1_000_000; long nrgPrice = 1; @@ -347,10 +348,8 @@ private AionAddress deployByteArrayContract() throws IOException { return tx.getContractAddress(); } - private AionAddress getNewRecipient(boolean isContractCreation) { - return (isContractCreation) - ? null - : new AionAddress(RandomUtils.nextBytes(AionAddress.SIZE)); + private Address getNewRecipient(boolean isContractCreation) { + return (isContractCreation) ? null : new AionAddress(RandomUtils.nextBytes(Address.SIZE)); } private byte[] extractActualOutput(byte[] rawOutput) { diff --git a/modApiServer/src/org/aion/api/server/Api.java b/modApiServer/src/org/aion/api/server/Api.java index 4600304cf1..af5000f459 100644 --- a/modApiServer/src/org/aion/api/server/Api.java +++ b/modApiServer/src/org/aion/api/server/Api.java @@ -22,6 +22,7 @@ import org.aion.solidity.Abi; import org.aion.solidity.CompilationResult; import org.aion.solidity.Compiler; +import org.aion.vm.api.interfaces.Address; import org.aion.zero.impl.blockchain.AionPendingStateImpl; import org.slf4j.Logger; @@ -63,11 +64,11 @@ public boolean unlockAccount( } public boolean unlockAccount( - final AionAddress _address, final String _password, final int _duration) { + final Address _address, final String _password, final int _duration) { return this.ACCOUNT_MANAGER.unlockAccount(_address, _password, _duration); } - public boolean lockAccount(final AionAddress _addr, final String _password) { + public boolean lockAccount(final Address _addr, final String _password) { return this.ACCOUNT_MANAGER.lockAccount(_addr, _password); } diff --git a/modApiServer/src/org/aion/api/server/ApiAion.java b/modApiServer/src/org/aion/api/server/ApiAion.java index 96c2a0f70f..da517f359e 100644 --- a/modApiServer/src/org/aion/api/server/ApiAion.java +++ b/modApiServer/src/org/aion/api/server/ApiAion.java @@ -353,7 +353,7 @@ protected AionTransaction getTransactionByHash(byte[] hash) { } } - public byte[] getCode(AionAddress addr) { + public byte[] getCode(Address addr) { return this.ac.getRepository().getCode(addr); } @@ -437,7 +437,7 @@ protected byte[] doCall(ArgTxCall _params) { } protected long estimateNrg(ArgTxCall params) { - AionAddress fromAddr = + Address fromAddr = (params.getFrom().isEmptyAddress()) ? AionAddress.ZERO_ADDRESS() : params.getFrom(); AionTransaction tx = new AionTransaction( @@ -460,7 +460,7 @@ protected ApiTxResponse createContract(ArgTxCall _params) { return (new ApiTxResponse(TxResponse.INVALID_TX)); } - AionAddress from = _params.getFrom(); + Address from = _params.getFrom(); if (from == null || from.isEmptyAddress()) { LOG.error(""); @@ -509,7 +509,7 @@ public BigInteger getBalance(String _address) { return this.ac.getRepository().getBalance(AionAddress.wrap(_address)); } - public BigInteger getBalance(AionAddress _address) { + public BigInteger getBalance(Address _address) { return this.ac.getRepository().getBalance(_address); } @@ -517,7 +517,7 @@ public BigInteger getNonce(String _address) { return this.ac.getRepository().getNonce(AionAddress.wrap(_address)); } - public BigInteger getNonce(AionAddress _address) { + public BigInteger getNonce(Address _address) { return this.ac.getRepository().getNonce(_address); } @@ -527,7 +527,7 @@ protected ApiTxResponse sendTransaction(ArgTxCall _params) { return (new ApiTxResponse(TxResponse.INVALID_TX)); } - AionAddress from = _params.getFrom(); + Address from = _params.getFrom(); if (from == null || from.isEmptyAddress()) { LOG.error(""); @@ -560,7 +560,8 @@ protected ApiTxResponse sendTransaction(ArgTxCall _params) { _params.getNrgPrice()); tx.sign(key); - return (new ApiTxResponse(pendingState.addPendingTransaction(tx), tx.getTransactionHash())); + return (new ApiTxResponse( + pendingState.addPendingTransaction(tx), tx.getTransactionHash())); } } catch (Exception ex) { LOG.error("ApiAion.sendTransaction exception: [{}]", ex.getMessage()); @@ -575,7 +576,8 @@ protected ApiTxResponse sendTransaction(byte[] signedTx) { AionTransaction tx = new AionTransaction(signedTx); try { - return (new ApiTxResponse(pendingState.addPendingTransaction(tx), tx.getTransactionHash())); + return (new ApiTxResponse( + pendingState.addPendingTransaction(tx), tx.getTransactionHash())); } catch (Exception ex) { LOG.error("", ex); return (new ApiTxResponse(TxResponse.EXCEPTION, ex)); @@ -583,7 +585,7 @@ protected ApiTxResponse sendTransaction(byte[] signedTx) { } protected AionTransaction signTransaction(ArgTxCall _params, String _address) { - AionAddress address; + Address address; if (_address == null || _address.isEmpty()) { LOG.error(""); return null; @@ -641,8 +643,8 @@ protected String[] getBootNodes() { // } // private synchronized BigInteger getTxNonce(ECKey key, boolean add) { - // return add ? nm.getNonceAndAdd(Address.wrap(key.getAddress())) : - // nm.getNonce(Address.wrap(key.getAddress())); + // return add ? nm.getNonceAndAdd(AionAddress.wrap(key.getAddress())) : + // nm.getNonce(AionAddress.wrap(key.getAddress())); // } public boolean isMining() { diff --git a/modApiServer/src/org/aion/api/server/ApiTxResponse.java b/modApiServer/src/org/aion/api/server/ApiTxResponse.java index 7c260adf01..a5ba15092e 100644 --- a/modApiServer/src/org/aion/api/server/ApiTxResponse.java +++ b/modApiServer/src/org/aion/api/server/ApiTxResponse.java @@ -1,7 +1,7 @@ package org.aion.api.server; -import org.aion.base.type.AionAddress; import org.aion.mcf.blockchain.TxResponse; +import org.aion.vm.api.interfaces.Address; public class ApiTxResponse { @@ -9,7 +9,7 @@ public class ApiTxResponse { private byte[] txHash; - private AionAddress contractAddress; + private Address contractAddress; // Could just store the exception message string private Exception ex; @@ -23,7 +23,7 @@ public class ApiTxResponse { this.txHash = txHash; } - ApiTxResponse(TxResponse rsp, byte[] txHash, AionAddress contractAddress) { + ApiTxResponse(TxResponse rsp, byte[] txHash, Address contractAddress) { this.rsp = rsp; this.txHash = txHash; this.contractAddress = contractAddress; @@ -82,7 +82,7 @@ public byte[] getTxHash() { return txHash; } - public AionAddress getContractAddress() { + public Address getContractAddress() { return contractAddress; } } diff --git a/modApiServer/src/org/aion/api/server/pb/ApiAion0.java b/modApiServer/src/org/aion/api/server/pb/ApiAion0.java index 633cc88fc7..6289ed3bb8 100644 --- a/modApiServer/src/org/aion/api/server/pb/ApiAion0.java +++ b/modApiServer/src/org/aion/api/server/pb/ApiAion0.java @@ -55,7 +55,6 @@ import org.aion.evtmgr.impl.evt.EventBlock; import org.aion.evtmgr.impl.evt.EventTx; import org.aion.mcf.account.Keystore; -import org.aion.mcf.vm.types.Log; import org.aion.p2p.INode; import org.aion.solidity.Abi; import org.aion.vm.api.interfaces.Address; @@ -115,7 +114,8 @@ protected void onBlock(AionBlockSummary cbs) { for (AionTxReceipt txr : txrs) { AionTransaction tx = txr.getTransaction(); Address contractAddress = - Optional.ofNullable(tx.getDestinationAddress()).orElse(tx.getContractAddress()); + Optional.ofNullable(tx.getDestinationAddress()) + .orElse(tx.getContractAddress()); Integer cnt = 0; txr.getLogInfoList() @@ -140,8 +140,10 @@ protected void onBlock(AionBlockSummary cbs) { for (AionTransaction t : txList) { if (Arrays.equals( - t.getTransactionHash(), - tx.getTransactionHash())) { + t + .getTransactionHash(), + tx + .getTransactionHash())) { break; } insideCnt++; @@ -188,7 +190,8 @@ protected void pendingTxReceived(ITransaction _tx) { protected void pendingTxUpdate(ITxReceipt _txRcpt, EventTx.STATE _state) { ByteArrayWrapper txHashW = - ByteArrayWrapper.wrap(((AionTxReceipt) _txRcpt).getTransaction().getTransactionHash()); + ByteArrayWrapper.wrap( + ((AionTxReceipt) _txRcpt).getTransaction().getTransactionHash()); if (LOG.isTraceEnabled()) { LOG.trace( @@ -555,7 +558,7 @@ public byte[] process(byte[] request, byte[] socketId) { try { Message.req_getBalance req = Message.req_getBalance.parseFrom(data); - AionAddress addr = AionAddress.wrap(req.getAddress().toByteArray()); + Address addr = AionAddress.wrap(req.getAddress().toByteArray()); balance = this.getBalance(addr); } catch (InvalidProtocolBufferException e) { @@ -586,7 +589,7 @@ public byte[] process(byte[] request, byte[] socketId) { try { Message.req_getNonce req = Message.req_getNonce.parseFrom(data); - AionAddress addr = AionAddress.wrap(req.getAddress().toByteArray()); + Address addr = AionAddress.wrap(req.getAddress().toByteArray()); nonce = this.getNonce(addr); } catch (InvalidProtocolBufferException e) { @@ -623,7 +626,8 @@ public byte[] process(byte[] request, byte[] socketId) { ApiUtil.toReturnHeader(getApiVersion(), Retcode.r_success_VALUE); return ApiUtil.combineRetMsg(retHeader, rsp.toByteArray()); } catch (Exception e) { - LOG.error("ApiAion0.process.getEnergyPrice exception: [{}]", e.getMessage()); + LOG.error( + "ApiAion0.process.getEnergyPrice exception: [{}]", e.getMessage()); return ApiUtil.toReturnHeader( getApiVersion(), Retcode.r_fail_function_exception_VALUE); } @@ -746,7 +750,7 @@ public byte[] process(byte[] request, byte[] socketId) { Message.req_getCode req; try { req = Message.req_getCode.parseFrom(data); - AionAddress to = AionAddress.wrap(req.getAddress().toByteArray()); + Address to = AionAddress.wrap(req.getAddress().toByteArray()); byte[] code = this.getCode(to); if (code == null) { @@ -797,7 +801,8 @@ public byte[] process(byte[] request, byte[] socketId) { .newBuilder() .setAddress( ByteString.copyFrom( - AionAddress.wrap(log.address).toBytes())) + AionAddress.wrap(log.address) + .toBytes())) .setData( ByteString.copyFrom( ByteUtil.hexStringToBytes(log.data))) @@ -866,8 +871,8 @@ public byte[] process(byte[] request, byte[] socketId) { try { req = Message.req_call.parseFrom(data); - AionAddress from = AionAddress.wrap(req.getFrom().toByteArray()); - AionAddress to = AionAddress.wrap(req.getTo().toByteArray()); + Address from = AionAddress.wrap(req.getFrom().toByteArray()); + Address to = AionAddress.wrap(req.getTo().toByteArray()); BigInteger value = new BigInteger(req.getValue().toByteArray()); byte[] d = req.getData().toByteArray(); @@ -1082,7 +1087,7 @@ public byte[] process(byte[] request, byte[] socketId) { try { req = Message.req_getTransactionCount.parseFrom(data); long blkNr = req.getBlocknumber(); - AionAddress addr = AionAddress.wrap(req.getAddress().toByteArray()); + Address addr = AionAddress.wrap(req.getAddress().toByteArray()); if (blkNr < -1) { return ApiUtil.toReturnHeader( @@ -1505,7 +1510,7 @@ public byte[] process(byte[] request, byte[] socketId) { getApiVersion(), Retcode.r_fail_function_exception_VALUE); } - Map addrMap = new HashMap<>(); + Map addrMap = new HashMap<>(); for (int i = 0; i < req.getKeyFileList().size() && i < ACCOUNT_CREATE_LIMIT; i++) { @@ -1514,7 +1519,7 @@ public byte[] process(byte[] request, byte[] socketId) { req.getKeyFile(i).getPassword()); } - Map res = + Map res = ((short) request[2] == Message.Funcs.f_exportAccounts_VALUE) ? Keystore.exportAccount(addrMap) : Keystore.backupAccount(addrMap); @@ -1890,14 +1895,17 @@ public byte[] process(byte[] request, byte[] socketId) { Map receipts = new HashMap<>(); for (AionTxReceipt r : bs.getReceipts()) { receipts.put( - new ByteArrayWrapper(r.getTransaction().getTransactionHash()), r); + new ByteArrayWrapper( + r.getTransaction().getTransactionHash()), + r); } List txns = b.getTransactionsList(); for (int j = 0; j < txns.size(); j++) { AionTransaction tx = txns.get(j); AionTxReceipt r = - receipts.get(new ByteArrayWrapper(tx.getTransactionHash())); + receipts.get( + new ByteArrayWrapper(tx.getTransactionHash())); if (r == null) { if (LOG.isDebugEnabled()) { LOG.debug( @@ -1912,13 +1920,15 @@ public byte[] process(byte[] request, byte[] socketId) { .getAionHub() .getBlockchain()) .getTransactionInfoLite( - tx.getTransactionHash(), b.getHash()); + tx.getTransactionHash(), + b.getHash()); r = ti.getReceipt(); } if (r == null) { LOG.error( "BlockSqlByRange: missing DB transaction: " - + ByteUtil.toHexString(tx.getTransactionHash())); + + ByteUtil.toHexString( + tx.getTransactionHash())); } else { transactionSql.add( generateTransactionSqlStatement( @@ -1947,7 +1957,8 @@ public byte[] process(byte[] request, byte[] socketId) { .getAionHub() .getBlockchain()) .getTransactionInfoLite( - tx.getTransactionHash(), + tx + .getTransactionHash(), b.getHash()); if (ti == null) { LOG.error( @@ -2117,14 +2128,17 @@ public byte[] process(byte[] request, byte[] socketId) { Map receipts = new HashMap<>(); for (AionTxReceipt r : bs.getReceipts()) { receipts.put( - new ByteArrayWrapper(r.getTransaction().getTransactionHash()), r); + new ByteArrayWrapper( + r.getTransaction().getTransactionHash()), + r); } List txns = b.getTransactionsList(); for (int j = 0; j < txns.size(); j++) { AionTransaction tx = txns.get(j); AionTxReceipt r = - receipts.get(new ByteArrayWrapper(tx.getTransactionHash())); + receipts.get( + new ByteArrayWrapper(tx.getTransactionHash())); if (r == null) { if (LOG.isDebugEnabled()) { LOG.debug( @@ -2139,13 +2153,15 @@ public byte[] process(byte[] request, byte[] socketId) { .getAionHub() .getBlockchain()) .getTransactionInfoLite( - tx.getTransactionHash(), b.getHash()); + tx.getTransactionHash(), + b.getHash()); r = ti.getReceipt(); } if (r == null) { LOG.error( "getBlockDetailsByRange: missing DB transaction: " - + ByteUtil.toHexString(tx.getTransactionHash())); + + ByteUtil.toHexString( + tx.getTransactionHash())); } else { txDetails.add( getTxDetailsObj( @@ -2175,7 +2191,8 @@ public byte[] process(byte[] request, byte[] socketId) { .getAionHub() .getBlockchain()) .getTransactionInfoLite( - tx.getTransactionHash(), + tx + .getTransactionHash(), b.getHash()); if (ti == null) { LOG.error( @@ -2354,7 +2371,8 @@ public byte[] process(byte[] request, byte[] socketId) { a -> { BigInteger b = this.getBalance( - AionAddress.wrap(a.toByteArray())); + AionAddress.wrap( + a.toByteArray())); Message.t_AccountDetail.Builder builder = Message.t_AccountDetail.newBuilder(); @@ -2456,7 +2474,9 @@ private Message.rsp_getTransaction getRsp_getTransaction(AionTransaction tx) { .setNonce(ByteString.copyFrom(tx.getNonce())) .setTo( ByteString.copyFrom( - tx.getDestinationAddress() == null ? EMPTY_BYTE_ARRAY : tx.getDestinationAddress().toBytes())) + tx.getDestinationAddress() == null + ? EMPTY_BYTE_ARRAY + : tx.getDestinationAddress().toBytes())) .setValue(ByteString.copyFrom(tx.getValue())) .setTxIndex((int) tx.getTxIndexInBlock()) .setTimeStamp(ByteUtil.byteArrayToLong(tx.getTimeStamp())) @@ -2547,7 +2567,11 @@ private Message.t_BlockDetail.Builder getBlockDetailsObj( } private Message.t_TxDetail getTxDetailsObj( - AionTransaction t, List _logs, int txIndex, long nrgConsumed, String error) { + AionTransaction t, + List _logs, + int txIndex, + long nrgConsumed, + String error) { List tles = _logs.parallelStream() @@ -2555,21 +2579,23 @@ private Message.t_TxDetail getTxDetailsObj( log -> { List topics = new ArrayList<>(); for (int i = 0; i < log.getLogTopics().size(); i++) { - topics.add(TypeConverter.toJsonHex(log.getLogTopics().get(i))); + topics.add( + TypeConverter.toJsonHex(log.getLogTopics().get(i))); } return Message.t_LgEle .newBuilder() .setData(ByteString.copyFrom(log.getLogData())) .setAddress( - ByteString.copyFrom(log.getLogSourceAddress().toBytes())) + ByteString.copyFrom( + log.getLogSourceAddress().toBytes())) .addAllTopics(topics) .build(); }) .filter(Objects::nonNull) .collect(Collectors.toList()); - AionAddress contract = t.getContractAddress(); + Address contract = t.getContractAddress(); Message.t_TxDetail.Builder tdBuilder = Message.t_TxDetail @@ -2676,7 +2702,11 @@ num_transactions bigint(64), } private String generateTransactionSqlStatement( - AionBlock b, AionTransaction t, List _logs, int txIndex, long nrgConsumed) { + AionBlock b, + AionTransaction t, + List _logs, + int txIndex, + long nrgConsumed) { JSONArray logs = new JSONArray(); for (IExecutionLog l : _logs) { JSONArray log = new JSONArray(); @@ -2802,7 +2832,8 @@ private List getRsp_getBlockDetails( .getAionHub() .getBlockchain()) .getTransactionInfoLite( - tx.getTransactionHash(), + tx + .getTransactionHash(), b.getHash()); List tles = diff --git a/modApiServer/src/org/aion/api/server/rpc/ApiWeb3Aion.java b/modApiServer/src/org/aion/api/server/rpc/ApiWeb3Aion.java index a728a403ba..5ccdf6b576 100644 --- a/modApiServer/src/org/aion/api/server/rpc/ApiWeb3Aion.java +++ b/modApiServer/src/org/aion/api/server/rpc/ApiWeb3Aion.java @@ -66,8 +66,8 @@ import org.aion.mcf.core.AccountState; import org.aion.mcf.core.ImportResult; import org.aion.mcf.vm.types.DataWord; -import org.aion.mcf.vm.types.Log; import org.aion.p2p.INode; +import org.aion.vm.api.interfaces.Address; import org.aion.vm.api.interfaces.IExecutionLog; import org.aion.zero.impl.AionBlockchainImpl; import org.aion.zero.impl.BlockContext; @@ -247,7 +247,7 @@ public AionBlock load(ByteArrayWrapper blockHash) { .build( new CacheLoader<>() { public MinerStatsView load(String key) { // no checked exception - AionAddress miner = new AionAddress(key); + Address miner = new AionAddress(key); return new MinerStatsView( STRATUM_RECENT_BLK_COUNT, miner.toBytes()) .update(); @@ -401,7 +401,7 @@ public RpcMsg eth_getBalance(Object _params) { return new RpcMsg(null, RpcError.INVALID_PARAMS, "Invalid parameters"); } - AionAddress address = new AionAddress(_address); + Address address = new AionAddress(_address); String bnOrId = "latest"; if (!JSONObject.NULL.equals(_bnOrId)) { @@ -440,7 +440,7 @@ public RpcMsg eth_getStorageAt(Object _params) { return new RpcMsg(null, RpcError.INVALID_PARAMS, "Invalid parameters"); } - AionAddress address = new AionAddress(_address); + Address address = new AionAddress(_address); String bnOrId = "latest"; if (!JSONObject.NULL.equals(_bnOrId)) { @@ -491,7 +491,7 @@ public RpcMsg eth_getTransactionCount(Object _params) { return new RpcMsg(null, RpcError.INVALID_PARAMS, "Invalid parameters"); } - AionAddress address = new AionAddress(_address); + Address address = new AionAddress(_address); String bnOrId = "latest"; if (!JSONObject.NULL.equals(_bnOrId)) { @@ -578,7 +578,7 @@ public RpcMsg eth_getCode(Object _params) { return new RpcMsg(null, RpcError.INVALID_PARAMS, "Invalid parameters"); } - AionAddress address = new AionAddress(_address); + Address address = new AionAddress(_address); String bnOrId = "latest"; if (!JSONObject.NULL.equals(_bnOrId)) { @@ -614,7 +614,7 @@ public RpcMsg eth_sign(Object _params) { return new RpcMsg(null, RpcError.INVALID_PARAMS, "Invalid parameters"); } - AionAddress address = AionAddress.wrap(_address); + Address address = AionAddress.wrap(_address); ECKey key = getAccountKey(address.toString()); if (key == null) { return new RpcMsg(null, RpcError.NOT_ALLOWED, "Account not unlocked."); @@ -1785,7 +1785,7 @@ public RpcMsg ops_getAccountState(Object _params) { return new RpcMsg(null, RpcError.INVALID_PARAMS, "Invalid parameters"); } - AionAddress address; + Address address; try { address = new AionAddress(_address); diff --git a/modApiServer/src/org/aion/api/server/types/ArgTxCall.java b/modApiServer/src/org/aion/api/server/types/ArgTxCall.java index 48d45e5ecd..e0b78560c9 100644 --- a/modApiServer/src/org/aion/api/server/types/ArgTxCall.java +++ b/modApiServer/src/org/aion/api/server/types/ArgTxCall.java @@ -1,7 +1,7 @@ package org.aion.api.server.types; -import static org.aion.mcf.vm.Constants.NRG_TRANSACTION_DEFAULT; import static org.aion.mcf.vm.Constants.NRG_CREATE_CONTRACT_DEFAULT; +import static org.aion.mcf.vm.Constants.NRG_TRANSACTION_DEFAULT; import java.math.BigInteger; import org.aion.base.type.AionAddress; @@ -9,14 +9,15 @@ import org.aion.base.util.TypeConverter; import org.aion.log.AionLoggerFactory; import org.aion.log.LogEnum; +import org.aion.vm.api.interfaces.Address; import org.json.JSONObject; import org.slf4j.Logger; /** @author chris */ public final class ArgTxCall { - private final AionAddress from; - private final AionAddress to; + private final Address from; + private final Address to; private final byte[] data; private final BigInteger nonce; private final BigInteger value; @@ -29,8 +30,8 @@ public final class ArgTxCall { // TODO: create a builder class for create this class public ArgTxCall( - final AionAddress _from, - final AionAddress _to, + final Address _from, + final Address _to, final byte[] _data, final BigInteger _nonce, final BigInteger _value, @@ -47,9 +48,9 @@ public ArgTxCall( public static ArgTxCall fromJSON(final JSONObject _jsonObj, long defaultNrgPrice) { try { - AionAddress from = AionAddress - .wrap(ByteUtil.hexStringToBytes(_jsonObj.optString("from", ""))); - AionAddress to = AionAddress.wrap(ByteUtil.hexStringToBytes(_jsonObj.optString("to", ""))); + Address from = + AionAddress.wrap(ByteUtil.hexStringToBytes(_jsonObj.optString("from", ""))); + Address to = AionAddress.wrap(ByteUtil.hexStringToBytes(_jsonObj.optString("to", ""))); byte[] data = ByteUtil.hexStringToBytes(_jsonObj.optString("data", "")); String nonceStr = _jsonObj.optString("nonce", "0x0"); @@ -87,11 +88,11 @@ public static ArgTxCall fromJSON(final JSONObject _jsonObj, long defaultNrgPrice } } - public AionAddress getFrom() { + public Address getFrom() { return this.from; } - public AionAddress getTo() { + public Address getTo() { return this.to; } diff --git a/modApiServer/test/org/aion/api/server/ApiAionTest.java b/modApiServer/test/org/aion/api/server/ApiAionTest.java index b6352dec1c..b4b3cd0737 100644 --- a/modApiServer/test/org/aion/api/server/ApiAionTest.java +++ b/modApiServer/test/org/aion/api/server/ApiAionTest.java @@ -26,6 +26,7 @@ import org.aion.mcf.account.AccountManager; import org.aion.mcf.account.Keystore; import org.aion.mcf.blockchain.TxResponse; +import org.aion.vm.api.interfaces.Address; import org.aion.zero.impl.blockchain.AionImpl; import org.aion.zero.impl.config.CfgAion; import org.aion.zero.impl.db.AionBlockStore; @@ -269,7 +270,7 @@ public void testGetTransactions() { public void testDoCall() { byte[] msg = "test message".getBytes(); - AionAddress addr = new AionAddress(Keystore.create("testPwd")); + Address addr = new AionAddress(Keystore.create("testPwd")); AccountManager.inst().unlockAccount(addr, "testPwd", 50000); AionTransaction tx = @@ -301,7 +302,7 @@ public void testDoCall() { public void testEstimates() { byte[] msg = "test message".getBytes(); - AionAddress addr = new AionAddress(Keystore.create("testPwd")); + Address addr = new AionAddress(Keystore.create("testPwd")); AccountManager.inst().unlockAccount(addr, "testPwd", 50000); @@ -368,7 +369,7 @@ public void testCreateContract() { // locked account should throw INVALID_ACCOUNT - AionAddress addr = new AionAddress(Keystore.create("testPwd")); + Address addr = new AionAddress(Keystore.create("testPwd")); txcall = new ArgTxCall( @@ -386,8 +387,11 @@ public void testCreateContract() { @Test public void testAccountGetters() { assertEquals( - repo.getBalance(AionAddress.ZERO_ADDRESS()), api.getBalance(AionAddress.ZERO_ADDRESS())); - assertEquals(repo.getNonce(AionAddress.ZERO_ADDRESS()), api.getNonce(AionAddress.ZERO_ADDRESS())); + repo.getBalance(AionAddress.ZERO_ADDRESS()), + api.getBalance(AionAddress.ZERO_ADDRESS())); + assertEquals( + repo.getNonce(AionAddress.ZERO_ADDRESS()), + api.getNonce(AionAddress.ZERO_ADDRESS())); assertEquals( repo.getBalance(AionAddress.ZERO_ADDRESS()), api.getBalance(AionAddress.ZERO_ADDRESS().toString())); @@ -435,7 +439,7 @@ public void testSendTransaction() { // locked account should throw INVALID_ACCOUNT - AionAddress addr = new AionAddress(Keystore.create("testPwd")); + Address addr = new AionAddress(Keystore.create("testPwd")); txcall = new ArgTxCall( @@ -458,7 +462,8 @@ public void testSimpleGetters() { api.initNrgOracle(impl); assertNotNull(api.getCoinbase()); - assertEquals(repo.getCode(AionAddress.ZERO_ADDRESS()), api.getCode(AionAddress.ZERO_ADDRESS())); + assertEquals( + repo.getCode(AionAddress.ZERO_ADDRESS()), api.getCode(AionAddress.ZERO_ADDRESS())); assertEquals(impl.getBlockMiner().isMining(), api.isMining()); assertArrayEquals(CfgAion.inst().getNodes(), api.getBootNodes()); assertEquals(impl.getAionHub().getP2pMgr().getActiveNodes().size(), api.peerCount()); diff --git a/modApiServer/test/org/aion/api/server/TxRecptLgTest.java b/modApiServer/test/org/aion/api/server/TxRecptLgTest.java index df5a4354d8..481c5b1bda 100644 --- a/modApiServer/test/org/aion/api/server/TxRecptLgTest.java +++ b/modApiServer/test/org/aion/api/server/TxRecptLgTest.java @@ -8,14 +8,13 @@ import java.math.BigInteger; import java.util.List; import org.aion.api.server.types.TxRecptLg; -import org.aion.base.type.AionAddress; import org.aion.base.util.ByteUtil; import org.aion.crypto.ECKey; import org.aion.crypto.HashUtil; import org.aion.mcf.core.ImportResult; -import org.aion.mcf.vm.types.Log; import org.aion.solidity.CompilationResult; import org.aion.solidity.Compiler; +import org.aion.vm.api.interfaces.Address; import org.aion.vm.api.interfaces.IExecutionLog; import org.aion.zero.impl.BlockContext; import org.aion.zero.impl.StandaloneBlockchain; @@ -89,9 +88,9 @@ public void TestTxRecptLg() throws InterruptedException, IOException { ImportResult result = bc.tryToConnect(context.block); assertEquals(result, ImportResult.IMPORTED_BEST); - AionAddress addressA = tx1.getContractAddress(); + Address addressA = tx1.getContractAddress(); System.out.println("contract A address = " + addressA); - AionAddress addressB = tx2.getContractAddress(); + Address addressB = tx2.getContractAddress(); System.out.println("contract B address = " + addressB); Thread.sleep(1000); diff --git a/modApiServer/test/org/aion/api/server/pb/ApiAion0Test.java b/modApiServer/test/org/aion/api/server/pb/ApiAion0Test.java index ec7946d719..47e3e05ce7 100644 --- a/modApiServer/test/org/aion/api/server/pb/ApiAion0Test.java +++ b/modApiServer/test/org/aion/api/server/pb/ApiAion0Test.java @@ -22,6 +22,7 @@ import org.aion.equihash.EquihashMiner; import org.aion.mcf.account.AccountManager; import org.aion.mcf.account.Keystore; +import org.aion.vm.api.interfaces.Address; import org.aion.zero.impl.Version; import org.aion.zero.impl.blockchain.AionImpl; import org.aion.zero.impl.config.CfgAion; @@ -190,7 +191,7 @@ public void testProcessMinerAddress() throws Exception { @Test public void testProcessAccountsValue() throws Exception { - AionAddress addr = new AionAddress(Keystore.create("testPwd")); + Address addr = new AionAddress(Keystore.create("testPwd")); rsp = sendRequest(Message.Servs.s_wallet_VALUE, Message.Funcs.f_accounts_VALUE); @@ -225,7 +226,7 @@ public void testProcessBlockNumber() throws Exception { @Test public void testProcessUnlockAccount() { - AionAddress addr = new AionAddress(Keystore.create("testPwd")); + Address addr = new AionAddress(Keystore.create("testPwd")); AccountManager.inst().unlockAccount(addr, "testPwd", 50000); Message.req_unlockAccount reqBody = @@ -255,7 +256,7 @@ public void testProcessUnlockAccount() { @Test public void testProcessGetBalance() throws Exception { - AionAddress addr = new AionAddress(Keystore.create("testPwd")); + Address addr = new AionAddress(Keystore.create("testPwd")); AccountManager.inst().unlockAccount(addr, "testPwd", 50000); @@ -287,7 +288,7 @@ public void testProcessGetBalance() throws Exception { @Test public void testProcessGetNonce() throws Exception { - AionAddress addr = new AionAddress(Keystore.create("testPwd")); + Address addr = new AionAddress(Keystore.create("testPwd")); AccountManager.inst().unlockAccount(addr, "testPwd", 50000); @@ -397,7 +398,7 @@ public void testProcessCompileFail() { @Test public void testProcessGetCode() throws Exception { - AionAddress addr = new AionAddress(Keystore.create("testPwd")); + Address addr = new AionAddress(Keystore.create("testPwd")); AccountManager.inst().unlockAccount(addr, "testPwd", 50000); @@ -474,7 +475,7 @@ public void testProcessGetTR() throws Exception { @Test public void testProcessCall() throws Exception { - AionAddress addr = new AionAddress(Keystore.create("testPwd")); + Address addr = new AionAddress(Keystore.create("testPwd")); AccountManager.inst().unlockAccount(addr, "testPwd", 50000); @@ -850,7 +851,10 @@ public void testProcessGetTxCount() throws Exception { .setBlocknumber(blk.getNumber()) .setAddress( ByteString.copyFrom( - blk.getTransactionsList().get(0).getSenderAddress().toBytes())) + blk.getTransactionsList() + .get(0) + .getSenderAddress() + .toBytes())) .build(); rsp = @@ -974,11 +978,14 @@ public void testProcessAccountCreateAndLock() throws Exception { assertEquals(3, rslt.getAddressCount()); ByteString addr = rslt.getAddress(0); assertTrue( - api.unlockAccount(AionAddress.wrap(rslt.getAddress(0).toByteArray()), "passwd0", 500)); + api.unlockAccount( + AionAddress.wrap(rslt.getAddress(0).toByteArray()), "passwd0", 500)); assertTrue( - api.unlockAccount(AionAddress.wrap(rslt.getAddress(1).toByteArray()), "passwd1", 500)); + api.unlockAccount( + AionAddress.wrap(rslt.getAddress(1).toByteArray()), "passwd1", 500)); assertTrue( - api.unlockAccount(AionAddress.wrap(rslt.getAddress(2).toByteArray()), "passwd2", 500)); + api.unlockAccount( + AionAddress.wrap(rslt.getAddress(2).toByteArray()), "passwd2", 500)); rsp = sendRequest(Message.Servs.s_hb_VALUE, Message.Funcs.f_accountCreate_VALUE); @@ -1057,7 +1064,9 @@ public void testProcessEstimateNrg() throws Exception { AionTransaction tx = new AionTransaction( - AionRepositoryImpl.inst().getNonce(AionAddress.ZERO_ADDRESS()).toByteArray(), + AionRepositoryImpl.inst() + .getNonce(AionAddress.ZERO_ADDRESS()) + .toByteArray(), AionAddress.ZERO_ADDRESS(), AionAddress.ZERO_ADDRESS(), val, @@ -1075,10 +1084,10 @@ public void testProcessEstimateNrg() throws Exception { @Test public void testProcessExportAccounts() throws Exception { - AionAddress addr1 = new AionAddress(Keystore.create("testPwd1")); + Address addr1 = new AionAddress(Keystore.create("testPwd1")); AccountManager.inst().unlockAccount(addr1, "testPwd1", 50000); - AionAddress addr2 = new AionAddress(Keystore.create("testPwd2")); + Address addr2 = new AionAddress(Keystore.create("testPwd2")); AccountManager.inst().unlockAccount(addr2, "testPwd12", 50000); Message.t_Key tkey1 = @@ -1155,10 +1164,10 @@ public void testProcessImportAccounts() throws Exception { @Test public void testProcessEventRegister() throws Exception { - AionAddress addr1 = new AionAddress(Keystore.create("testPwd1")); + Address addr1 = new AionAddress(Keystore.create("testPwd1")); AccountManager.inst().unlockAccount(addr1, "testPwd1", 50000); - AionAddress addr2 = new AionAddress(Keystore.create("testPwd2")); + Address addr2 = new AionAddress(Keystore.create("testPwd2")); AccountManager.inst().unlockAccount(addr2, "testPwd12", 50000); Message.t_FilterCt fil1 = @@ -1356,7 +1365,7 @@ public void testProcessBlocksLatest() throws Exception { @Test public void testProcessAccountDetails() throws Exception { - AionAddress addr = new AionAddress(Keystore.create("testPwd")); + Address addr = new AionAddress(Keystore.create("testPwd")); AccountManager.inst().unlockAccount(addr, "testPwd", 50000); Message.req_getAccountDetailsByAddressList reqBody = diff --git a/modApiServer/test/org/aion/api/server/rpc/ApiWeb3AionTest.java b/modApiServer/test/org/aion/api/server/rpc/ApiWeb3AionTest.java index c40ebc8224..fbd3832847 100644 --- a/modApiServer/test/org/aion/api/server/rpc/ApiWeb3AionTest.java +++ b/modApiServer/test/org/aion/api/server/rpc/ApiWeb3AionTest.java @@ -8,6 +8,7 @@ import org.aion.base.type.AionAddress; import org.aion.mcf.account.AccountManager; import org.aion.mcf.account.Keystore; +import org.aion.vm.api.interfaces.Address; import org.aion.zero.impl.blockchain.AionImpl; import org.aion.zero.impl.blockchain.AionPendingStateImpl; import org.json.JSONArray; @@ -28,11 +29,11 @@ public void setup() { @Test public void testEthSignTransaction() { - AionAddress addr = new AionAddress(Keystore.create("testPwd")); + Address addr = new AionAddress(Keystore.create("testPwd")); AccountManager.inst().unlockAccount(addr, "testPwd", 50000); - AionAddress toAddr = new AionAddress(Keystore.create("testPwd")); + Address toAddr = new AionAddress(Keystore.create("testPwd")); JSONObject tx = new JSONObject(); tx.put("from", "0x" + addr.toString()); @@ -77,11 +78,11 @@ public void testEthSignTransaction() { @Test public void testEthSignTransactionAddressParamIsNull() { - AionAddress addr = new AionAddress(Keystore.create("testPwd")); + Address addr = new AionAddress(Keystore.create("testPwd")); AccountManager.inst().unlockAccount(addr, "testPwd", 50000); - AionAddress toAddr = new AionAddress(Keystore.create("testPwd")); + Address toAddr = new AionAddress(Keystore.create("testPwd")); JSONObject tx = new JSONObject(); tx.put("from", addr.toString()); @@ -105,9 +106,9 @@ public void testEthSignTransactionAddressParamIsNull() { @Test public void testEthSignTransactionAccountNotUnlocked() { - AionAddress addr = new AionAddress(Keystore.create("testPwd")); + Address addr = new AionAddress(Keystore.create("testPwd")); - AionAddress toAddr = new AionAddress(Keystore.create("testPwd")); + Address toAddr = new AionAddress(Keystore.create("testPwd")); JSONObject tx = new JSONObject(); tx.put("from", addr.toString()); @@ -131,9 +132,9 @@ public void testEthSignTransactionAccountNotUnlocked() { @Test public void testEthSendTransactionAccountNotUnlocked() { - AionAddress addr = new AionAddress(Keystore.create("testPwd")); + Address addr = new AionAddress(Keystore.create("testPwd")); - AionAddress toAddr = new AionAddress(Keystore.create("testPwd")); + Address toAddr = new AionAddress(Keystore.create("testPwd")); JSONObject tx = new JSONObject(); tx.put("from", addr.toString()); @@ -165,8 +166,8 @@ public void testEthGetTransactionCountPending() { assertNull(rsp.getError()); assertEquals( - impl.getPendingState().getNonce(AionAddress.ZERO_ADDRESS()), - StringHexToBigInteger(rsp.getResult().toString())); + impl.getPendingState().getNonce(AionAddress.ZERO_ADDRESS()), + StringHexToBigInteger(rsp.getResult().toString())); } @Test @@ -179,8 +180,8 @@ public void testEthGetBalancePending() { assertNull(rsp.getError()); assertEquals( - impl.getPendingState().getBalance(AionAddress.ZERO_ADDRESS()), - StringHexToBigInteger(rsp.getResult().toString())); + impl.getPendingState().getBalance(AionAddress.ZERO_ADDRESS()), + StringHexToBigInteger(rsp.getResult().toString())); } @Test diff --git a/modMcf/src/org/aion/mcf/account/AccountManager.java b/modMcf/src/org/aion/mcf/account/AccountManager.java index 027119a85d..ab22648bee 100644 --- a/modMcf/src/org/aion/mcf/account/AccountManager.java +++ b/modMcf/src/org/aion/mcf/account/AccountManager.java @@ -6,10 +6,10 @@ import java.util.List; import java.util.Map; import java.util.Optional; -import org.aion.base.type.AionAddress; import org.aion.crypto.ECKey; import org.aion.log.AionLoggerFactory; import org.aion.log.LogEnum; +import org.aion.vm.api.interfaces.Address; import org.slf4j.Logger; /** Account Manger Class */ @@ -19,7 +19,7 @@ public class AccountManager { public static final int UNLOCK_MAX = 86400, // sec UNLOCK_DEFAULT = 60; // sec - private Map accounts; + private Map accounts; private AccountManager() { LOGGER.debug(""); @@ -37,7 +37,7 @@ public static AccountManager inst() { // Retrieve ECKey from active accounts list from manager perspective // !important method. use in careful // Can use this method as check if unlocked - public ECKey getKey(final AionAddress _address) { + public ECKey getKey(final Address _address) { Account acc = this.accounts.get(_address); @@ -56,7 +56,7 @@ public List getAccounts() { return new ArrayList<>(this.accounts.values()); } - public boolean unlockAccount(AionAddress _address, String _password, int _timeout) { + public boolean unlockAccount(Address _address, String _password, int _timeout) { ECKey key = Keystore.getKey(_address.toString(), _password); @@ -90,7 +90,7 @@ public boolean unlockAccount(AionAddress _address, String _password, int _timeou } } - public boolean lockAccount(AionAddress _address, String _password) { + public boolean lockAccount(Address _address, String _password) { ECKey key = Keystore.getKey(_address.toString(), _password); diff --git a/modMcf/src/org/aion/mcf/account/Keystore.java b/modMcf/src/org/aion/mcf/account/Keystore.java index 0736cd0479..107971ea65 100644 --- a/modMcf/src/org/aion/mcf/account/Keystore.java +++ b/modMcf/src/org/aion/mcf/account/Keystore.java @@ -31,6 +31,7 @@ import org.aion.log.LogEnum; import org.aion.util.bytes.ByteUtil; import org.aion.util.conversions.Hex; +import org.aion.vm.api.interfaces.Address; import org.slf4j.Logger; /** key store class. */ @@ -96,14 +97,13 @@ public static String create(String password, ECKey key) { } } - public static Map exportAccount( - Map account) { + public static Map exportAccount(Map account) { if (account == null) { throw new NullPointerException(); } - Map res = new HashMap<>(); - for (Map.Entry entry : account.entrySet()) { + Map res = new HashMap<>(); + for (Map.Entry entry : account.entrySet()) { ECKey eckey = Keystore.getKey(entry.getKey().toString(), entry.getValue()); if (eckey != null) { res.put(entry.getKey(), ByteArrayWrapper.wrap(eckey.getPrivKeyBytes())); @@ -113,8 +113,7 @@ public static Map exportAccount( return res; } - public static Map backupAccount( - Map account) { + public static Map backupAccount(Map account) { if (account == null) { throw new NullPointerException(); } @@ -141,13 +140,13 @@ public static Map backupAccount( .toString()))) .collect(Collectors.toList()); - Map res = new HashMap<>(); + Map res = new HashMap<>(); for (File file : matchedFile) { try { String[] frags = file.getName().split("--"); if (frags.length == 3) { if (frags[2].startsWith(AION_PREFIX)) { - AionAddress addr = AionAddress.wrap(frags[2]); + Address addr = AionAddress.wrap(frags[2]); byte[] content = Files.readAllBytes(file.toPath()); String pw = account.get(addr); diff --git a/modMcf/src/org/aion/mcf/core/IBlockchain.java b/modMcf/src/org/aion/mcf/core/IBlockchain.java index f9993e77d9..2c0d65b634 100644 --- a/modMcf/src/org/aion/mcf/core/IBlockchain.java +++ b/modMcf/src/org/aion/mcf/core/IBlockchain.java @@ -3,7 +3,6 @@ import java.math.BigInteger; import java.util.List; import java.util.Map; -import org.aion.base.type.AionAddress; import org.aion.base.type.IBlock; import org.aion.base.type.ITransaction; import org.aion.base.util.ByteArrayWrapper; @@ -11,6 +10,7 @@ import org.aion.mcf.types.AbstractBlockHeader; import org.aion.mcf.types.AbstractBlockSummary; import org.aion.mcf.types.AbstractTxReceipt; +import org.aion.vm.api.interfaces.Address; /** * Blockchain interface. @@ -114,7 +114,7 @@ void dropImported( void setExitOn(long exitOn); - AionAddress getMinerCoinbase(); + Address getMinerCoinbase(); boolean isBlockExist(byte[] hash); diff --git a/modMcf/src/org/aion/mcf/types/AbstractBlockHeader.java b/modMcf/src/org/aion/mcf/types/AbstractBlockHeader.java index ceade6d5c3..42741ba569 100644 --- a/modMcf/src/org/aion/mcf/types/AbstractBlockHeader.java +++ b/modMcf/src/org/aion/mcf/types/AbstractBlockHeader.java @@ -3,6 +3,7 @@ import java.math.BigInteger; import org.aion.base.type.AionAddress; import org.aion.log.AionLoggerFactory; +import org.aion.vm.api.interfaces.Address; import org.spongycastle.util.BigIntegers; /** Abstract BlockHeader. */ @@ -101,12 +102,12 @@ public byte[] getParentHash() { return parentHash; } - public AionAddress getCoinbase() { + public Address getCoinbase() { return coinbase; } - public void setCoinbase(AionAddress coinbase) { - this.coinbase = coinbase; + public void setCoinbase(Address coinbase) { + this.coinbase = (AionAddress) coinbase; } public byte[] getStateRoot() { diff --git a/modMcf/src/org/aion/mcf/types/AbstractBlockSummary.java b/modMcf/src/org/aion/mcf/types/AbstractBlockSummary.java index 686ca559b0..dab6452575 100644 --- a/modMcf/src/org/aion/mcf/types/AbstractBlockSummary.java +++ b/modMcf/src/org/aion/mcf/types/AbstractBlockSummary.java @@ -15,6 +15,7 @@ import org.aion.rlp.RLP; import org.aion.rlp.RLPElement; import org.aion.rlp.RLPList; +import org.aion.vm.api.interfaces.Address; import org.slf4j.Logger; /** AbstractBlockSummary */ @@ -25,7 +26,7 @@ public class AbstractBlockSummary< TXES extends ITxExecSummary> { protected BLK block; - protected Map rewards; + protected Map rewards; protected List receipts; protected List summaries; protected BigInteger totalDifficulty = BigInteger.ZERO; @@ -44,12 +45,12 @@ public List getSummaries() { return summaries; } - protected static byte[] encodeRewards(Map rewards) { + protected static byte[] encodeRewards(Map rewards) { return encodeMap( rewards, - new Functional.Function() { + new Functional.Function() { @Override - public byte[] apply(AionAddress address) { + public byte[] apply(Address address) { return RLP.encodeElement(address.toBytes()); } }, @@ -61,12 +62,12 @@ public byte[] apply(BigInteger reward) { }); } - protected static Map decodeRewards(RLPList rewards) { + protected static Map decodeRewards(RLPList rewards) { return decodeMap( rewards, - new Functional.Function() { + new Functional.Function() { @Override - public AionAddress apply(byte[] bytes) { + public Address apply(byte[] bytes) { return AionAddress.wrap(bytes); } }, @@ -84,7 +85,7 @@ public BigInteger apply(byte[] bytes) { * All the mining rewards paid out for this block, including the main block rewards, uncle * rewards, and transaction fees. */ - public Map getRewards() { + public Map getRewards() { return rewards; } diff --git a/modMcf/test/org/aion/mcf/account/AccountManagerTest.java b/modMcf/test/org/aion/mcf/account/AccountManagerTest.java index 33c76adb67..a8805ff199 100644 --- a/modMcf/test/org/aion/mcf/account/AccountManagerTest.java +++ b/modMcf/test/org/aion/mcf/account/AccountManagerTest.java @@ -14,6 +14,7 @@ import org.aion.base.type.AionAddress; import org.aion.crypto.ECKey; import org.aion.crypto.ECKeyFac; +import org.aion.vm.api.interfaces.Address; import org.junit.After; import org.junit.AfterClass; import org.junit.BeforeClass; @@ -21,7 +22,7 @@ public class AccountManagerTest { private static AccountManager accountManager = AccountManager.inst(); - private AionAddress notRegistered = + private Address notRegistered = AionAddress.wrap("a011111111111111111111111111111101010101010101010101010101010101"); private final int DEFAULT_TEST_TIMEOUT = 10; diff --git a/modMcf/test/org/aion/mcf/account/KeystoreTest.java b/modMcf/test/org/aion/mcf/account/KeystoreTest.java index fb68b3a6d0..2bc2b902a9 100644 --- a/modMcf/test/org/aion/mcf/account/KeystoreTest.java +++ b/modMcf/test/org/aion/mcf/account/KeystoreTest.java @@ -18,6 +18,7 @@ import org.aion.crypto.ECKey; import org.aion.crypto.ECKeyFac; import org.aion.util.bytes.ByteUtil; +import org.aion.vm.api.interfaces.Address; import org.junit.After; import org.junit.Before; import org.junit.Test; @@ -128,10 +129,10 @@ public void testAccountExport() { String addr = Keystore.create(password, key); assertEquals(addr.substring(2), ByteUtil.toHexString(key.getAddress())); - Map arg = new HashMap<>(); + Map arg = new HashMap<>(); arg.put(AionAddress.wrap(addr), password); - Map export = Keystore.exportAccount(arg); + Map export = Keystore.exportAccount(arg); assertTrue(export.containsKey(AionAddress.wrap(addr))); assertTrue(export.containsValue(ByteArrayWrapper.wrap(key.getPrivKeyBytes()))); @@ -147,10 +148,10 @@ public void testAccountBackup() { String addr = Keystore.create(password, key); assertEquals(addr.substring(2), ByteUtil.toHexString(key.getAddress())); - Map arg = new HashMap<>(); + Map arg = new HashMap<>(); arg.put(AionAddress.wrap(addr), password); - Map export = Keystore.backupAccount(arg); + Map export = Keystore.backupAccount(arg); assertNotNull(export); diff --git a/modMcf/test/org/aion/mcf/db/AionRepositoryCacheTest.java b/modMcf/test/org/aion/mcf/db/AionRepositoryCacheTest.java index 440ef8db9e..9b7870c98b 100644 --- a/modMcf/test/org/aion/mcf/db/AionRepositoryCacheTest.java +++ b/modMcf/test/org/aion/mcf/db/AionRepositoryCacheTest.java @@ -18,6 +18,7 @@ import org.aion.mcf.config.CfgPrune; import org.aion.mcf.vm.types.DataWord; import org.aion.mcf.vm.types.DoubleDataWord; +import org.aion.vm.api.interfaces.Address; import org.aion.zero.db.AionRepositoryCache; import org.aion.zero.impl.db.AionRepositoryImpl; import org.aion.zero.impl.db.ContractDetailsAion; @@ -74,7 +75,7 @@ public void testGetStorageValueNoSuchAddress() { @Test public void testGetStorageValueIsSingleZero() { - AionAddress address = getNewAddress(); + Address address = getNewAddress(); IDataWord key = new DataWord(RandomUtils.nextBytes(DataWord.BYTES)); cache.removeStorageRow(address, key.toWrapper()); assertNull(cache.getStorageValue(address, key.toWrapper())); @@ -86,7 +87,7 @@ public void testGetStorageValueIsSingleZero() { @Test public void testGetStorageValueIsDoubleZero() { - AionAddress address = getNewAddress(); + Address address = getNewAddress(); IDataWord key = new DataWord(RandomUtils.nextBytes(DataWord.BYTES)); cache.removeStorageRow(address, key.toWrapper()); assertNull(cache.getStorageValue(address, key.toWrapper())); @@ -98,7 +99,7 @@ public void testGetStorageValueIsDoubleZero() { @Test public void testGetStorageValueWithSingleZeroKey() { - AionAddress address = getNewAddress(); + Address address = getNewAddress(); ByteArrayWrapper value = new DataWord(RandomUtils.nextBytes(DataWord.BYTES)).toWrapper(); cache.addStorageRow(address, DataWord.ZERO.toWrapper(), value); assertEquals(value, cache.getStorageValue(address, DataWord.ZERO.toWrapper())); @@ -110,7 +111,7 @@ public void testGetStorageValueWithSingleZeroKey() { @Test public void testGetStorageValueWithDoubleZeroKey() { - AionAddress address = getNewAddress(); + Address address = getNewAddress(); ByteArrayWrapper value = new DataWord(RandomUtils.nextBytes(DataWord.BYTES)).toWrapper(); cache.addStorageRow(address, DoubleDataWord.ZERO.toWrapper(), value); assertEquals(value, cache.getStorageValue(address, DoubleDataWord.ZERO.toWrapper())); @@ -122,7 +123,7 @@ public void testGetStorageValueWithDoubleZeroKey() { @Test public void testGetStorageValueWithZeroKeyAndValue() { - AionAddress address = getNewAddress(); + Address address = getNewAddress(); // single-single cache.removeStorageRow(address, DataWord.ZERO.toWrapper()); @@ -143,7 +144,7 @@ public void testGetStorageValueWithZeroKeyAndValue() { @Test public void testOverwriteValueWithSingleZero() { - AionAddress address = getNewAddress(); + Address address = getNewAddress(); ByteArrayWrapper key = new DataWord(RandomUtils.nextBytes(DataWord.BYTES)).toWrapper(); ByteArrayWrapper value = new DoubleDataWord(RandomUtils.nextBytes(DoubleDataWord.BYTES)).toWrapper(); @@ -155,7 +156,7 @@ public void testOverwriteValueWithSingleZero() { @Test public void testOverwriteValueWithDoubleZero() { - AionAddress address = getNewAddress(); + Address address = getNewAddress(); ByteArrayWrapper key = new DoubleDataWord(RandomUtils.nextBytes(DoubleDataWord.BYTES)).toWrapper(); ByteArrayWrapper value = new DataWord(RandomUtils.nextBytes(DataWord.BYTES)).toWrapper(); @@ -170,16 +171,16 @@ public void testGetStorageValueEnMass() { int numEntries = RandomUtils.nextInt(300, 700); int deleteOdds = 5; int numAddrs = 8; - List addresses = getAddressesInBulk(numAddrs); + List

addresses = getAddressesInBulk(numAddrs); List keys = getKeysInBulk(numEntries); List values = getValuesInBulk(numEntries); - for (AionAddress address : addresses) { + for (Address address : addresses) { massAddToCache(address, keys, values); deleteEveryNthEntry(address, keys, deleteOdds); } - for (AionAddress address : addresses) { + for (Address address : addresses) { checkStorage(address, keys, values, deleteOdds); } } @@ -187,12 +188,12 @@ public void testGetStorageValueEnMass() { // <-----------------------------------------HELPERS--------------------------------------------> /** Returns a new random address. */ - private AionAddress getNewAddress() { - return new AionAddress(RandomUtils.nextBytes(AionAddress.SIZE)); + private Address getNewAddress() { + return new AionAddress(RandomUtils.nextBytes(Address.SIZE)); } - private List getAddressesInBulk(int num) { - List addresses = new ArrayList<>(num); + private List
getAddressesInBulk(int num) { + List
addresses = new ArrayList<>(num); for (int i = 0; i < num; i++) { addresses.add(getNewAddress()); } @@ -204,10 +205,7 @@ private List getAddressesInBulk(int num) { * keys and values, where it is assumed every n'th pair was deleted. */ private void checkStorage( - AionAddress address, - List keys, - List values, - int n) { + Address address, List keys, List values, int n) { Map storage = cache.getStorage(address, keys); int count = 1; for (ByteArrayWrapper key : keys) { @@ -224,7 +222,7 @@ private void checkStorage( * Iterates over every key in keys -- which are assumed to exist in cache -- and then deletes * any key-value pair in cache for every n'th key in keys. */ - private void deleteEveryNthEntry(AionAddress address, List keys, int n) { + private void deleteEveryNthEntry(Address address, List keys, int n) { int count = 1; for (ByteArrayWrapper key : keys) { if (count % n == 0) { @@ -236,7 +234,7 @@ private void deleteEveryNthEntry(AionAddress address, List key /** Puts all of the key-value pairs in keys and values into cache under address. */ private void massAddToCache( - AionAddress address, List keys, List values) { + Address address, List keys, List values) { int size = keys.size(); assertEquals(size, values.size()); for (int i = 0; i < size; i++) { diff --git a/modPrecompiled/src/org/aion/precompiled/ContractFactory.java b/modPrecompiled/src/org/aion/precompiled/ContractFactory.java index b185c1a1e3..e8cda8205f 100644 --- a/modPrecompiled/src/org/aion/precompiled/ContractFactory.java +++ b/modPrecompiled/src/org/aion/precompiled/ContractFactory.java @@ -9,6 +9,7 @@ import org.aion.precompiled.contracts.TXHashContract; import org.aion.precompiled.contracts.TotalCurrencyContract; import org.aion.precompiled.type.PrecompiledContract; +import org.aion.vm.api.interfaces.Address; import org.aion.vm.api.interfaces.KernelInterface; import org.aion.vm.api.interfaces.TransactionContext; @@ -101,7 +102,7 @@ public PrecompiledContract getPrecompiledContract( * @param address The address to check. * @return true iff address is address of a pre-compiled contract. */ - public static boolean isPrecompiledContract(AionAddress address) { + public static boolean isPrecompiledContract(Address address) { switch (address.toString()) { case ADDR_TOKEN_BRIDGE: case ADDR_ED_VERIFY: @@ -119,7 +120,7 @@ public static boolean isPrecompiledContract(AionAddress address) { * * @return the contract address. */ - public static AionAddress getTotalCurrencyContractAddress() { + public static Address getTotalCurrencyContractAddress() { return AionAddress.wrap(ADDR_TOTAL_CURRENCY); } @@ -128,7 +129,7 @@ public static AionAddress getTotalCurrencyContractAddress() { * * @return the contract address */ - public static AionAddress getEdVerifyContractAddress() { + public static Address getEdVerifyContractAddress() { return AionAddress.wrap(ADDR_ED_VERIFY); } @@ -137,7 +138,7 @@ public static AionAddress getEdVerifyContractAddress() { * * @return the contract address */ - public static AionAddress getTxHashContractAddress() { + public static Address getTxHashContractAddress() { return AionAddress.wrap(ADDR_TX_HASH); } @@ -146,7 +147,7 @@ public static AionAddress getTxHashContractAddress() { * * @return the contract address */ - public static AionAddress getBlake2bHashContractAddress() { + public static Address getBlake2bHashContractAddress() { return AionAddress.wrap(ADDR_BLAKE2B_HASH); } } diff --git a/modPrecompiled/src/org/aion/precompiled/contracts/ATB/BridgeController.java b/modPrecompiled/src/org/aion/precompiled/contracts/ATB/BridgeController.java index 02c9eb34a6..a4dd1dde9a 100644 --- a/modPrecompiled/src/org/aion/precompiled/contracts/ATB/BridgeController.java +++ b/modPrecompiled/src/org/aion/precompiled/contracts/ATB/BridgeController.java @@ -10,7 +10,6 @@ import java.util.Collections; import java.util.List; import javax.annotation.Nonnull; -import org.aion.base.type.AionAddress; import org.aion.base.util.ByteUtil; import org.aion.crypto.ISignature; import org.aion.crypto.SignatureFac; @@ -18,6 +17,7 @@ import org.aion.precompiled.PrecompiledResultCode; import org.aion.precompiled.PrecompiledTransactionResult; import org.aion.precompiled.PrecompiledUtilities; +import org.aion.vm.api.interfaces.Address; import org.aion.vm.api.interfaces.TransactionSideEffects; /** @@ -28,15 +28,15 @@ public class BridgeController { private final BridgeStorageConnector connector; private final TransactionSideEffects result; - private final AionAddress contractAddress; - private final AionAddress ownerAddress; + private final Address contractAddress; + private final Address ownerAddress; private Transferable transferable; public BridgeController( @Nonnull final BridgeStorageConnector storageConnector, @Nonnull final TransactionSideEffects helper, - @Nonnull final AionAddress contractAddress, - @Nonnull final AionAddress ownerAddress) { + @Nonnull final Address contractAddress, + @Nonnull final Address ownerAddress) { this.connector = storageConnector; this.result = helper; this.contractAddress = contractAddress; diff --git a/modPrecompiled/src/org/aion/precompiled/contracts/ATB/BridgeStorageConnector.java b/modPrecompiled/src/org/aion/precompiled/contracts/ATB/BridgeStorageConnector.java index 764cf2b3f3..12e9557efc 100644 --- a/modPrecompiled/src/org/aion/precompiled/contracts/ATB/BridgeStorageConnector.java +++ b/modPrecompiled/src/org/aion/precompiled/contracts/ATB/BridgeStorageConnector.java @@ -4,7 +4,6 @@ import java.util.Arrays; import javax.annotation.Nonnull; import org.aion.base.db.IRepositoryCache; -import org.aion.base.type.AionAddress; import org.aion.base.util.ByteArrayWrapper; import org.aion.base.util.ByteUtil; import org.aion.crypto.HashUtil; @@ -13,6 +12,7 @@ import org.aion.mcf.vm.types.DataWord; import org.aion.mcf.vm.types.DoubleDataWord; import org.aion.precompiled.PrecompiledUtilities; +import org.aion.vm.api.interfaces.Address; /** * Storage layout mapping as the following: @@ -67,11 +67,11 @@ private enum M_ID { } private final IRepositoryCache> track; - private final AionAddress contractAddress; + private final Address contractAddress; public BridgeStorageConnector( @Nonnull final IRepositoryCache> track, - @Nonnull final AionAddress contractAddress) { + @Nonnull final Address contractAddress) { this.track = track; this.contractAddress = contractAddress; } diff --git a/modPrecompiled/src/org/aion/precompiled/contracts/ATB/TokenBridgeContract.java b/modPrecompiled/src/org/aion/precompiled/contracts/ATB/TokenBridgeContract.java index 555f900cf8..4bf228a854 100644 --- a/modPrecompiled/src/org/aion/precompiled/contracts/ATB/TokenBridgeContract.java +++ b/modPrecompiled/src/org/aion/precompiled/contracts/ATB/TokenBridgeContract.java @@ -19,6 +19,7 @@ import org.aion.precompiled.PrecompiledResultCode; import org.aion.precompiled.PrecompiledTransactionResult; import org.aion.precompiled.type.StatefulPrecompiledContract; +import org.aion.vm.api.interfaces.Address; import org.aion.vm.api.interfaces.TransactionContext; import org.aion.zero.types.AionInternalTx; @@ -33,7 +34,7 @@ public class TokenBridgeContract extends StatefulPrecompiledContract implements private final BridgeStorageConnector connector; private final BridgeController controller; - private final AionAddress contractAddress; + private final Address contractAddress; // some useful defaults // TODO: add passing returns (need more though on gas consumption) @@ -41,8 +42,8 @@ public class TokenBridgeContract extends StatefulPrecompiledContract implements public TokenBridgeContract( @Nonnull final TransactionContext context, @Nonnull final IRepositoryCache> track, - @Nonnull final AionAddress ownerAddress, - @Nonnull final AionAddress contractAddress) { + @Nonnull final Address ownerAddress, + @Nonnull final Address contractAddress) { super(track); this.context = context; this.track = track; @@ -265,8 +266,8 @@ public PrecompiledTransactionResult transfer( return new PrecompiledTransactionResult(PrecompiledResultCode.FAILURE, 0); // assemble an internal transaction - AionAddress from = this.contractAddress; - AionAddress recipient = new AionAddress(to); + Address from = this.contractAddress; + Address recipient = new AionAddress(to); BigInteger nonce = this.track.getNonce(from); DataWord valueToSend = new DataWord(value); byte[] dataToSend = new byte[0]; @@ -290,12 +291,7 @@ public PrecompiledTransactionResult transfer( *

NOTE: copied from {@code Callback} */ private AionInternalTx newInternalTx( - AionAddress from, - AionAddress to, - BigInteger nonce, - DataWord value, - byte[] data, - String note) { + Address from, Address to, BigInteger nonce, DataWord value, byte[] data, String note) { byte[] parentHash = context.getTransactionHash(); int depth = context.getTransactionStackDepth(); int index = context.getSideEffects().getInternalTransactions().size(); diff --git a/modPrecompiled/src/org/aion/precompiled/contracts/AionAuctionContract.java b/modPrecompiled/src/org/aion/precompiled/contracts/AionAuctionContract.java index d5a8d62380..4e148fea5d 100644 --- a/modPrecompiled/src/org/aion/precompiled/contracts/AionAuctionContract.java +++ b/modPrecompiled/src/org/aion/precompiled/contracts/AionAuctionContract.java @@ -30,6 +30,7 @@ import org.aion.precompiled.PrecompiledResultCode; import org.aion.precompiled.PrecompiledTransactionResult; import org.aion.precompiled.type.StatefulPrecompiledContract; +import org.aion.vm.api.interfaces.Address; import org.apache.commons.collections4.map.LRUMap; /** @@ -42,27 +43,27 @@ * @author William */ public class AionAuctionContract extends StatefulPrecompiledContract { - private static final AionAddress AION = + private static final Address AION = AionAddress.wrap("0xa0eeaeabdbc92953b072afbd21f3e3fd8a4a4f5e6a6e22200db746ab75e9a99a"); - private AionAddress activeDomainsAddress = + private Address activeDomainsAddress = AionAddress.wrap("0000000000000000000000000000000000000000000000000000000000000600"); - private AionAddress activeDomainsAddressTime = + private Address activeDomainsAddressTime = AionAddress.wrap("0000000000000000000000000000000000000000000000000000000000000601"); - private AionAddress activeDomainsAddressName = + private Address activeDomainsAddressName = AionAddress.wrap("0000000000000000000000000000000000000000000000000000000000000602"); - private AionAddress activeDomainsAddressValue = + private Address activeDomainsAddressValue = AionAddress.wrap("0000000000000000000000000000000000000000000000000000000000000603"); - private AionAddress auctionDomainsAddress = + private Address auctionDomainsAddress = AionAddress.wrap("0000000000000000000000000000000000000000000000000000000000000700"); - private AionAddress auctionDomainsAddressName = + private Address auctionDomainsAddressName = AionAddress.wrap("0000000000000000000000000000000000000000000000000000000000000702"); - private AionAddress allAddresses = + private Address allAddresses = AionAddress.wrap("0000000000000000000000000000000000000000000000000000000000000800"); - private AionAddress domainNameAddressPair = + private Address domainNameAddressPair = AionAddress.wrap("0000000000000000000000000000000000000000000000000000000000000801"); - private AionAddress domainAddressNamePair = + private Address domainAddressNamePair = AionAddress.wrap("0000000000000000000000000000000000000000000000000000000000000802"); private static final long COST = 20000L; @@ -83,11 +84,11 @@ public class AionAuctionContract extends StatefulPrecompiledContract { private static int LRU_MAP_SIZE = 4; // this should be changed - private final AionAddress callerAddress; + private final Address callerAddress; private final IBlockchain blockchain; private static Timer timer = new Timer(); private static LRUMap auctionsMap = new LRUMap<>(LRU_MAP_SIZE); - private static LRUMap> auctionBidsMap = + private static LRUMap> auctionBidsMap = new LRUMap<>(LRU_MAP_SIZE); private static final Set privateAionDomainNames = new HashSet<>(Arrays.asList("network.aion", "foundation.aion", "enterprise.aion")); @@ -100,7 +101,7 @@ public class AionAuctionContract extends StatefulPrecompiledContract { */ public AionAuctionContract( IRepositoryCache> track, - AionAddress address, + Address address, IBlockchain blockchain) { super(track); this.callerAddress = address; @@ -170,7 +171,7 @@ public PrecompiledTransactionResult execute(byte[] input, long nrg) { byte[] sign = new byte[SIG_LEN]; byte[] domainNameInBytes = new byte[domainNameLength]; String domainName; - AionAddress domainAddress; + Address domainAddress; int offset = 0; offset++; @@ -203,7 +204,7 @@ public PrecompiledTransactionResult execute(byte[] input, long nrg) { domainName = domainName.substring(0, 32); Ed25519Signature sig = Ed25519Signature.fromBytes(sign); - AionAddress bidderAddress = AionAddress.wrap(bidderAddressInByte); + Address bidderAddress = AionAddress.wrap(bidderAddressInByte); // user should have the signature signed with its callerAddress byte[] data = new byte[ADDR_LEN]; @@ -293,7 +294,7 @@ else if (isAuctionDomain(domainAddress)) { * @param domainAddress callerAddress of the domain bid for */ private void addToAuctionDomain( - AionAddress domainAddress, String domainName, String domainNameRaw) { + Address domainAddress, String domainName, String domainNameRaw) { Date currentDate = new Date(); Date finishDate = new Date(currentDate.getTime() + AUCTION_TIME.intValue()); // 3 days later, 3s @@ -316,7 +317,7 @@ private void addToAuctionDomain( // record to data base, change stuff, so when its time for task to execute, it will first check // database // to see if it has been extended, if it has, schedule new task. - private PrecompiledTransactionResult extensionRequest(AionAddress domainAddress, long nrg) { + private PrecompiledTransactionResult extensionRequest(Address domainAddress, long nrg) { Date expireDateFromStorage = getDateFromStorage(activeDomainsAddressTime, domainAddress); // Date currentDate = new Date(blockchain.getBestBlock().getTimestamp()); Date currentDate = new Date(); @@ -347,10 +348,7 @@ private PrecompiledTransactionResult extensionRequest(AionAddress domainAddress, * @param ownerAddress new owner of the given domain */ private void addToActiveDomains( - AionAddress domainAddress, - AionAddress ownerAddress, - String domainName, - BigInteger value) { + Address domainAddress, Address ownerAddress, String domainName, BigInteger value) { Date currentDate = new Date(); Date finishDate = new Date(currentDate.getTime() + ACTIVE_TIME.intValue()); // 1 year later, 5s @@ -378,10 +376,7 @@ private void addToActiveDomains( * @param value the bid value */ private void processBid( - String domainNameRaw, - AionAddress domainAddress, - AionAddress bidderAddress, - BigInteger value) { + String domainNameRaw, Address domainAddress, Address bidderAddress, BigInteger value) { this.track.getAccountState(bidderAddress).subFromBalance(value); BigInteger numberOfBids = getBigIntegerFromStorage(domainAddress, BID_KEY_COUNTER); @@ -424,7 +419,7 @@ private void processBid( // if domain is not in bids LRUMap // create the map and put into bids LRUMap else { - Map bids = new HashMap<>(); + Map bids = new HashMap<>(); bids.put(bidderAddress, value); auctionBidsMap.put(domainNameRaw, bids); } @@ -437,7 +432,7 @@ private void processBid( * * @param domainAddress The domain callerAddress of the auction to be processed */ - private void processAuction(AionAddress domainAddress) { + private void processAuction(Address domainAddress) { BigInteger numberOfBids = getBigIntegerFromStorage(domainAddress, BID_KEY_COUNTER); // if there are no bids, cancel the auction, no one wins, this should never happen @@ -445,11 +440,11 @@ private void processAuction(AionAddress domainAddress) { if (numberOfBids.intValue() < 1) return; String domainName; - AionAddress winnerAddress = null; + Address winnerAddress = null; BigInteger highestBid = MINIMUM_AMOUNT; BigInteger secondHighestBid = new BigInteger("0"); - AionAddress tempAddress; + Address tempAddress; BigInteger tempAmount; for (int i = 0; i < numberOfBids.intValue(); i++) { @@ -520,7 +515,7 @@ private byte[] fillByteArray(byte[] inputBytes) { * @param domainAddress a domain callerAddress * @return the trimmed byte array */ - private boolean isActiveDomain(AionAddress domainAddress) { + private boolean isActiveDomain(Address domainAddress) { DataWord key = new DataWord(blake128(domainAddress.toBytes())); return !(this.track .getStorageValue(activeDomainsAddress, key.toWrapper()) @@ -532,7 +527,7 @@ private boolean isActiveDomain(AionAddress domainAddress) { * * @param domainAddress a domain callerAddress */ - private boolean isAuctionDomain(AionAddress domainAddress) { + private boolean isAuctionDomain(Address domainAddress) { DataWord key = new DataWord(blake128(domainAddress.toBytes())); ByteArrayWrapper ret = this.track.getStorageValue(auctionDomainsAddress, key.toWrapper()); return !ret.equals(DoubleDataWord.ZERO.toWrapper()); @@ -548,7 +543,7 @@ private boolean isAuctionDomain(AionAddress domainAddress) { * @param value the bid value */ private void addBidToRepo( - AionAddress domainAddress, int offset, AionAddress bidderAddress, BigInteger value) { + Address domainAddress, int offset, Address bidderAddress, BigInteger value) { addBigIntegerToStorage(domainAddress, BID_KEY_VALUE + offset, value); addAddressToStorage(domainAddress, BID_KEY_ADDR + offset, bidderAddress); } @@ -561,10 +556,7 @@ private void addBidToRepo( * @param value the value (second highest) to deposit */ private void printWinner( - AionAddress domainAddress, - AionAddress winnerAddress, - BigInteger value, - String domainName) { + Address domainAddress, Address winnerAddress, BigInteger value, String domainName) { System.out.println("Auction result for domain at: '" + domainAddress + "'"); System.out.println(" Domain name: " + domainName); System.out.println(" New domain owner: " + winnerAddress); @@ -579,7 +571,7 @@ private void printWinner( * * @param domainAddress callerAddress of the domain */ - private void printRemoveActiveDomain(AionAddress domainAddress) { + private void printRemoveActiveDomain(Address domainAddress) { System.out.println("Removing active domain at: " + domainAddress); Date terminateDate = new Date(); System.out.println(" Terminate time at: " + terminateDate.toString()); @@ -591,7 +583,7 @@ private void printRemoveActiveDomain(AionAddress domainAddress) { * * @param domainAddress callerAddress of the domain */ - private void removeActiveDomain(AionAddress domainAddress, long expireTime) { + private void removeActiveDomain(Address domainAddress, long expireTime) { // retrieve expire time from storage Date expireDateFromStorage = getDateFromStorage(activeDomainsAddressTime, domainAddress); @@ -608,7 +600,7 @@ private void removeActiveDomain(AionAddress domainAddress, long expireTime) { } // return deposit - AionAddress ownerAddress = getAddressFromStorage(activeDomainsAddress, domainAddress); + Address ownerAddress = getAddressFromStorage(activeDomainsAddress, domainAddress); BigInteger tempValue = getBigIntegerFromStorage(activeDomainsAddressValue, domainAddress); this.track.addBalance(ownerAddress, tempValue); @@ -702,9 +694,9 @@ private boolean hasActiveParentDomain(String domainName) { * @param domainName name of the domain * @return callerAddress generated for the domain */ - private AionAddress createAddressForDomain(String domainName) { + private Address createAddressForDomain(String domainName) { ECKey domainAddr = ECKeyFac.inst().create(); - AionAddress domainAddress = AionAddress.wrap(domainAddr.getAddress()); + Address domainAddress = AionAddress.wrap(domainAddr.getAddress()); // store callerAddress -> name pair & name -> callerAddress pair addNameToStorage(domainAddressNamePair, domainAddress, domainName); @@ -739,7 +731,7 @@ private AionAddress getAddressFromName(String domainName) { * * @param domainAddress callerAddress of domain */ - private void storeNewAddress(AionAddress domainAddress) { + private void storeNewAddress(Address domainAddress) { BigInteger counter = getBigIntegerFromStorage(allAddresses, ALL_ADDR_COUNTER_KEY); this.track.addStorageRow( allAddresses, @@ -748,7 +740,7 @@ private void storeNewAddress(AionAddress domainAddress) { addAddressToStorage(allAddresses, ALL_ADDR_KEY + counter, domainAddress); } - private AionAddress getAddressFromStorage(AionAddress key, AionAddress key2) { + private Address getAddressFromStorage(Address key, Address key2) { byte[] addrFirstPart = this.track .getStorageValue(key, new DataWord(blake128(key2.toBytes())).toWrapper()) @@ -761,7 +753,7 @@ key, new DataWord(blake128(blake128(key2.toBytes()))).toWrapper()) return AionAddress.wrap(combineTwoBytes(addrFirstPart, addrSecondPart)); } - private AionAddress getAddressFromStorage(AionAddress key, String key2) { + private Address getAddressFromStorage(Address key, String key2) { byte[] addrFirstPart = this.track .getStorageValue(key, new DataWord(blake128(key2.getBytes())).toWrapper()) @@ -774,20 +766,20 @@ key, new DataWord(blake128(blake128(key2.getBytes()))).toWrapper()) return AionAddress.wrap(combineTwoBytes(addrFirstPart, addrSecondPart)); } - private BigInteger getBigIntegerFromStorage(AionAddress key, String key2) { + private BigInteger getBigIntegerFromStorage(Address key, String key2) { ByteArrayWrapper data = this.track.getStorageValue( key, new DataWord(blake128(key2.getBytes())).toWrapper()); return new BigInteger(data.getData()); } - private BigInteger getBigIntegerFromStorage(AionAddress key, AionAddress key2) { + private BigInteger getBigIntegerFromStorage(Address key, Address key2) { ByteArrayWrapper data = this.track.getStorageValue(key, new DataWord(blake128(key2.toBytes())).toWrapper()); return new BigInteger(data.getData()); } - private String getNameFromStorage(AionAddress key, AionAddress key2) { + private String getNameFromStorage(Address key, Address key2) { byte[] domainNameFirstPart = this.track .getStorageValue(key, new DataWord(blake128(key2.toBytes())).toWrapper()) @@ -810,7 +802,7 @@ key, new DataWord(blake128(blake128(key2.toBytes()))).toWrapper()) return tempDomainName + ".aion"; } - private Date getDateFromStorage(AionAddress key, AionAddress key2) { + private Date getDateFromStorage(Address key, Address key2) { byte[] expireDateData = this.track .getStorageValue(key, new DataWord(blake128(key2.toBytes())).toWrapper()) @@ -825,7 +817,7 @@ private Date getDateFromStorage(AionAddress key, AionAddress key2) { return new Date(Long.parseLong(expireDateStr)); } - private void addAddressToStorage(AionAddress key, AionAddress key2, AionAddress value) { + private void addAddressToStorage(Address key, Address key2, Address value) { byte[] addrFirstPart = new byte[16]; byte[] addrSecondPart = new byte[16]; System.arraycopy(value.toBytes(), 0, addrFirstPart, 0, 16); @@ -841,7 +833,7 @@ private void addAddressToStorage(AionAddress key, AionAddress key2, AionAddress new DataWord(addrSecondPart).toWrapper()); } - private void addAddressToStorage(AionAddress key, String key2, AionAddress value) { + private void addAddressToStorage(Address key, String key2, Address value) { byte[] addrFirstPart = new byte[16]; byte[] addrSecondPart = new byte[16]; System.arraycopy(value.toBytes(), 0, addrFirstPart, 0, 16); @@ -857,7 +849,7 @@ private void addAddressToStorage(AionAddress key, String key2, AionAddress value new DataWord(addrSecondPart).toWrapper()); } - private void addDateToStorage(AionAddress key, AionAddress key2, Date value) { + private void addDateToStorage(Address key, Address key2, Date value) { long dateInLong = value.getTime(); String dateString = String.valueOf(dateInLong); byte[] date; @@ -875,7 +867,7 @@ private void addDateToStorage(AionAddress key, AionAddress key2, Date value) { new DataWord(fillByteArray(date)).toWrapper()); } - private void addNameToStorage(AionAddress key, AionAddress key2, String name) { + private void addNameToStorage(Address key, Address key2, String name) { byte[] nameFirstPart = name.substring(0, 16).getBytes(); byte[] nameSecondPart = name.substring(16, 32).getBytes(); this.track.addStorageRow( @@ -888,7 +880,7 @@ private void addNameToStorage(AionAddress key, AionAddress key2, String name) { new DataWord(nameSecondPart).toWrapper()); } - private void addNameToStorage2(AionAddress key, AionAddress key2, String name) { + private void addNameToStorage2(Address key, Address key2, String name) { byte[] addZeros = addLeadingZeros(name.getBytes()); byte[] value1 = new byte[16], value2 = new byte[16]; System.arraycopy(addZeros, 0, value1, 0, 16); @@ -903,14 +895,14 @@ private void addNameToStorage2(AionAddress key, AionAddress key2, String name) { new DataWord(value2).toWrapper()); } - private void addBigIntegerToStorage(AionAddress key, String key2, BigInteger value) { + private void addBigIntegerToStorage(Address key, String key2, BigInteger value) { this.track.addStorageRow( key, new DataWord(blake128(key2.getBytes())).toWrapper(), new DataWord(value).toWrapper()); } - private void addBigIntegerToStorage(AionAddress key, AionAddress key2, BigInteger value) { + private void addBigIntegerToStorage(Address key, Address key2, BigInteger value) { this.track.addStorageRow( key, new DataWord(blake128(key2.toBytes())).toWrapper(), @@ -920,9 +912,9 @@ private void addBigIntegerToStorage(AionAddress key, AionAddress key2, BigIntege // tasks // ---------------------------------------------------------------------------------------------------------// class finishAuction extends TimerTask { - AionAddress domainAddress; + Address domainAddress; - finishAuction(AionAddress input) { + finishAuction(Address input) { domainAddress = input; } @@ -935,10 +927,10 @@ public void run() { } class removeActiveDomain extends TimerTask { - AionAddress domainAddress; + Address domainAddress; long time; - removeActiveDomain(AionAddress input, long time) { + removeActiveDomain(Address input, long time) { domainAddress = input; this.time = time; } @@ -1010,7 +1002,7 @@ private List getAllAuctionDomains() { List auctions = new ArrayList<>(); for (int i = 0; i < numberOfDomainsTotal.intValue(); i++) { - AionAddress tempDomainAddr = getAddressFromStorage(allAddresses, ALL_ADDR_KEY + i); + Address tempDomainAddr = getAddressFromStorage(allAddresses, ALL_ADDR_KEY + i); // if domain exists if (!this.track @@ -1031,12 +1023,12 @@ private List getAllAuctionDomains() { return auctions; } - private HashMap getBidsForADomain(AionAddress domainAddress) { - HashMap bids = new HashMap<>(); + private HashMap getBidsForADomain(Address domainAddress) { + HashMap bids = new HashMap<>(); BigInteger numberOfBids = getBigIntegerFromStorage(domainAddress, BID_KEY_COUNTER); for (int i = 0; i < numberOfBids.intValue(); i++) { - AionAddress bidderAddr = getAddressFromStorage(domainAddress, BID_KEY_ADDR + i); + Address bidderAddr = getAddressFromStorage(domainAddress, BID_KEY_ADDR + i); BigInteger bidAmount = getBigIntegerFromStorage(domainAddress, BID_KEY_VALUE + i); // check if there is multiple bids from same callerAddress @@ -1070,7 +1062,7 @@ public void displayAllAuctionDomains() { } public void displayMyBidsLRU(ECKey key) { - AionAddress callerAddress = AionAddress.wrap(key.getAddress()); + Address callerAddress = AionAddress.wrap(key.getAddress()); boolean hasNoBids = true; System.out.println( @@ -1083,7 +1075,7 @@ public void displayMyBidsLRU(ECKey key) { List auctionDomainsList = getAllAuctionDomains(); for (AuctionDomainsData domain : auctionDomainsList) { - AionAddress tempDomainAddress = domain.domainAddress; + Address tempDomainAddress = domain.domainAddress; String tempDomainName = domain.domainName; auctionBidsMap.put(tempDomainName, getBidsForADomain(tempDomainAddress)); @@ -1100,7 +1092,7 @@ public void displayMyBidsLRU(ECKey key) { } public void displayMyBidForDomainLRU(String domainNameRaw, ECKey key) { - AionAddress callerAddress = AionAddress.wrap(key.getAddress()); + Address callerAddress = AionAddress.wrap(key.getAddress()); System.out.println( "--------------------------AION NAME SERVICE QUERY: displayMyBidForDomainLRU--------------------------"); @@ -1114,7 +1106,7 @@ public void displayMyBidForDomainLRU(String domainNameRaw, ECKey key) { domainNameRaw.substring(0, domainNameRaw.length() - 5).getBytes(); String domainName2 = new String(addLeadingZeros(domainNameInBytes)); String domainName = domainName2.substring(5, 37); - AionAddress domainAddress = getAddressFromStorage(domainNameAddressPair, domainName); + Address domainAddress = getAddressFromStorage(domainNameAddressPair, domainName); // if the domain is not in auction, print error and return if (this.track @@ -1148,7 +1140,7 @@ public void displayAuctionDomainLRU(String domainNameRaw) { String domainName2 = new String(addLeadingZeros(domainNameInBytes)); String domainName = domainName2.substring(5, 37); - AionAddress domainAddress = getAddressFromStorage(domainNameAddressPair, domainName); + Address domainAddress = getAddressFromStorage(domainNameAddressPair, domainName); // if the domain is not in auction, return if (this.track @@ -1190,20 +1182,20 @@ private void printAuctionDomain(String domainName) { " Number of bids for this domain: " + auctionsMap.get(domainName).numberOfBids); } - private void printBid(String domainName, AionAddress bidderAddress) { + private void printBid(String domainName, Address bidderAddress) { System.out.println("Domain name: " + domainName); System.out.println(" Bid value: " + auctionBidsMap.get(domainName).get(bidderAddress)); } class AuctionDomainsData { String domainName; - AionAddress domainAddress; + Address domainAddress; Date completeDate; BigInteger numberOfBids; AuctionDomainsData( String domainName, - AionAddress domainAddress, + Address domainAddress, Date completeDate, BigInteger numberOfBids) { this.domainName = domainName; diff --git a/modPrecompiled/src/org/aion/precompiled/contracts/AionNameServiceContract.java b/modPrecompiled/src/org/aion/precompiled/contracts/AionNameServiceContract.java index 485e505b78..6ab5be7d38 100644 --- a/modPrecompiled/src/org/aion/precompiled/contracts/AionNameServiceContract.java +++ b/modPrecompiled/src/org/aion/precompiled/contracts/AionNameServiceContract.java @@ -22,6 +22,7 @@ import org.aion.precompiled.PrecompiledResultCode; import org.aion.precompiled.PrecompiledTransactionResult; import org.aion.precompiled.type.StatefulPrecompiledContract; +import org.aion.vm.api.interfaces.Address; import org.apache.commons.collections4.map.LRUMap; /** @@ -37,7 +38,7 @@ public class AionNameServiceContract extends StatefulPrecompiledContract { // set to a default cost for now, this will need to be adjusted - private static final Map domains = new HashMap<>(); + private static final Map domains = new HashMap<>(); private static final long SET_COST = 1000; private static final long TRANSFER_COST = 2000; private static final String RESOLVER_HASH = "ResolverHash"; @@ -46,26 +47,26 @@ public class AionNameServiceContract extends StatefulPrecompiledContract { private static final String ALL_ADDR_KEY = "allAddressKey"; private static final String ALL_ADDR_COUNTER_KEY = "allAddressKey"; - private AionAddress activeDomainsAddress = + private Address activeDomainsAddress = AionAddress.wrap("0000000000000000000000000000000000000000000000000000000000000600"); - private AionAddress activeDomainsAddressTime = + private Address activeDomainsAddressTime = AionAddress.wrap("0000000000000000000000000000000000000000000000000000000000000601"); - private AionAddress activeDomainsAddressValue = + private Address activeDomainsAddressValue = AionAddress.wrap("0000000000000000000000000000000000000000000000000000000000000603"); - private AionAddress allAddresses = + private Address allAddresses = AionAddress.wrap("0000000000000000000000000000000000000000000000000000000000000800"); - private AionAddress domainAddressNamePair = + private Address domainAddressNamePair = AionAddress.wrap("0000000000000000000000000000000000000000000000000000000000000802"); - private AionAddress registeredDomainAddressName = + private Address registeredDomainAddressName = AionAddress.wrap("0000000000000000000000000000000000000000000000000000000000000803"); - private AionAddress registeredDomainNameAddress = + private Address registeredDomainNameAddress = AionAddress.wrap("0000000000000000000000000000000000000000000000000000000000000804"); - private AionAddress address; - private AionAddress ownerAddress; - private AionAddress ownerAddressKey; - private AionAddress resolverAddressKey; - private AionAddress TTLKey; + private Address address; + private Address ownerAddress; + private Address ownerAddressKey; + private Address resolverAddressKey; + private Address TTLKey; private String domainName; private static LRUMap activeDomains = @@ -74,8 +75,8 @@ public class AionNameServiceContract extends StatefulPrecompiledContract { /** Construct a new ANS Contract */ public AionNameServiceContract( IRepositoryCache> track, - AionAddress address, - AionAddress ownerAddress) { // byte + Address address, + Address ownerAddress) { // byte super(track); this.address = address; setUpKeys(); @@ -284,7 +285,7 @@ private PrecompiledTransactionResult transferSubdomainOwnership( if (!isValidOwnerAddress(AionAddress.wrap(combineTwoBytes(addr1, addr2)))) return new PrecompiledTransactionResult(PrecompiledResultCode.FAILURE, nrg); - AionAddress sdAddress = AionAddress.wrap(subdomainAddress); + Address sdAddress = AionAddress.wrap(subdomainAddress); if (isSubdomain(subdomain)) { this.track.addStorageRow( @@ -337,7 +338,7 @@ private void storeResult(byte[] hash1, byte[] hash2, byte[] addr1, byte[] addr2) this.address, new DataWord(hash2).toWrapper(), new DataWord(addr2).toWrapper()); } - private AionAddress getValueFromStorage(AionAddress key) { + private Address getValueFromStorage(Address key) { if (key == null) return null; byte[] byteKey = key.toBytes(); byte[] key1 = new byte[16]; @@ -357,7 +358,7 @@ private AionAddress getValueFromStorage(AionAddress key) { return (new AionAddress(addrCombined)); } - private void addToRegistered(AionAddress domainAddress, String domainName) { + private void addToRegistered(Address domainAddress, String domainName) { // set up domain name for storage byte[] domainNameInBytes = domainName.getBytes(); byte[] domainNameInBytesWithLeadingZeros = addLeadingZeros(domainNameInBytes); @@ -408,13 +409,13 @@ private boolean isSubdomain(String subdomainName) { return true; } - private boolean isValidDomainAddress(AionAddress domainAddress) { + private boolean isValidDomainAddress(Address domainAddress) { // checks if the given domain address is valid under the aion domain String rawAddress = domainAddress.toString(); return rawAddress.charAt(0) == 'a' && rawAddress.charAt(1) == '0'; } - private boolean isValidOwnerAddress(AionAddress ownerAddress) { + private boolean isValidOwnerAddress(Address ownerAddress) { // checks if the owner address is registered in the repository if (this.track.hasAccountState(ownerAddress)) return true; return (this.track.hasContractDetails(ownerAddress)); @@ -439,7 +440,7 @@ private byte[] trimTrailingZeros(byte[] b) { return ret; } - private boolean isAvailableDomain(AionAddress domainAddress, AionAddress ownerAddress) { + private boolean isAvailableDomain(Address domainAddress, Address ownerAddress) { ByteArrayWrapper addrFirstPart = this.track.getStorageValue( activeDomainsAddress, @@ -448,7 +449,7 @@ private boolean isAvailableDomain(AionAddress domainAddress, AionAddress ownerAd this.track.getStorageValue( activeDomainsAddress, new DataWord(blake128(blake128(domainAddress.toBytes()))).toWrapper()); - AionAddress addrFromRepo = + Address addrFromRepo = AionAddress.wrap( combineTwoBytes(addrFirstPart.getData(), addrSecondPart.getData())); @@ -456,19 +457,19 @@ private boolean isAvailableDomain(AionAddress domainAddress, AionAddress ownerAd } /** getter functions */ - public AionAddress getResolverAddress() { + public Address getResolverAddress() { return getValueFromStorage(this.resolverAddressKey); } - public AionAddress getTTL() { + public Address getTTL() { return getValueFromStorage(this.TTLKey); } - public AionAddress getOwnerAddress() { + public Address getOwnerAddress() { return getValueFromStorage(this.ownerAddressKey); } - public AionAddress getOwnerAddress(AionAddress key) { + public Address getOwnerAddress(Address key) { return getValueFromStorage(key); } @@ -511,7 +512,7 @@ private byte[] addLeadingZeros(byte[] b) { return ret; } - private String getDomainNameFromAddress(AionAddress domainAddress) { + private String getDomainNameFromAddress(Address domainAddress) { String rawDomainName = ""; ByteArrayWrapper nameFirstPartData = this.track.getStorageValue( @@ -556,7 +557,7 @@ private List getAllActiveDomains() { this.track .getStorageValue(allAddresses, new DataWord(secondHash).toWrapper()) .getData(); - AionAddress tempDomainAddr = + Address tempDomainAddr = AionAddress.wrap(combineTwoBytes(addrFirstPart, addrSecondPart)); // if domain exists @@ -579,7 +580,7 @@ private List getAllActiveDomains() { new DataWord(blake128(blake128(tempDomainAddr.toBytes()))) .toWrapper()) .getData(); - AionAddress tempOwnerAddr = + Address tempOwnerAddr = AionAddress.wrap(combineTwoBytes(ownerAddrFirstPart, ownerAddrSecondPart)); byte[] expireDateData = @@ -668,7 +669,7 @@ public void displayAllActiveDomains() { } public void displayMyDomains(ECKey key) { - AionAddress callerAddress = AionAddress.wrap(key.getAddress()); + Address callerAddress = AionAddress.wrap(key.getAddress()); System.out.println( "----------------------------AION NAME SERVICE QUERY: displayMyDomains-----------------------------"); @@ -719,7 +720,7 @@ public void displayRegisteredDomains() { System.out.println(); } - public String getRegisteredDomainName(AionAddress domainAddress) { + public String getRegisteredDomainName(Address domainAddress) { byte[] domainNameFirstPart = this.track .getStorageValue( @@ -750,7 +751,7 @@ public String getRegisteredDomainName(AionAddress domainAddress) { return domainName; } - public AionAddress getRegisteredDomainAddress(String domainName) { + public Address getRegisteredDomainAddress(String domainName) { byte[] addressFirstPart = this.track .getStorageValue( @@ -772,15 +773,15 @@ public AionAddress getRegisteredDomainAddress(String domainName) { // data structures used to store pass data for query class ActiveDomainsData { String domainName; - AionAddress domainAddress; - AionAddress ownerAddress; + Address domainAddress; + Address ownerAddress; Date expireDate; BigInteger auctionValue; ActiveDomainsData( String domainName, - AionAddress domainAddress, - AionAddress ownerAddress, + Address domainAddress, + Address ownerAddress, Date expireDate, BigInteger auctionValue) { this.domainName = domainName; diff --git a/modPrecompiled/src/org/aion/precompiled/contracts/MultiSignatureContract.java b/modPrecompiled/src/org/aion/precompiled/contracts/MultiSignatureContract.java index 2d5304308a..28249317f7 100644 --- a/modPrecompiled/src/org/aion/precompiled/contracts/MultiSignatureContract.java +++ b/modPrecompiled/src/org/aion/precompiled/contracts/MultiSignatureContract.java @@ -21,6 +21,7 @@ import org.aion.precompiled.PrecompiledResultCode; import org.aion.precompiled.PrecompiledTransactionResult; import org.aion.precompiled.type.StatefulPrecompiledContract; +import org.aion.vm.api.interfaces.Address; /** * An N of M implementation of a multi-signature pre-compiled contract. @@ -43,7 +44,7 @@ public final class MultiSignatureContract extends StatefulPrecompiledContract { private static final int AMOUNT_LEN = 128; private static final int SIG_LEN = 96; private static final int ADDR_LEN = 32; - private final AionAddress caller; + private final Address caller; public static final int MAX_OWNERS = 10; public static final int MIN_OWNERS = 2; @@ -58,7 +59,7 @@ public final class MultiSignatureContract extends StatefulPrecompiledContract { * @throws IllegalArgumentException if track or caller are null. */ public MultiSignatureContract( - IRepositoryCache> track, AionAddress caller) { + IRepositoryCache> track, Address caller) { super(track); if (caller == null) { @@ -76,14 +77,14 @@ public MultiSignatureContract( * @param owners The proposed owners of the new multi-sig wallet. * @return a byte array for executing a create-wallet operation. */ - public static byte[] constructCreateWalletInput(long threshold, List owners) { - int len = 1 + Long.BYTES + (owners.size() * AionAddress.SIZE); + public static byte[] constructCreateWalletInput(long threshold, List

owners) { + int len = 1 + Long.BYTES + (owners.size() * Address.SIZE); byte[] input = new byte[len]; ByteBuffer buffer = ByteBuffer.allocate(len); buffer.put(new byte[] {(byte) 0x0}); buffer.putLong(threshold); - for (AionAddress addr : owners) { + for (Address addr : owners) { buffer.put(addr.toBytes()); } @@ -105,25 +106,20 @@ public static byte[] constructCreateWalletInput(long threshold, List signatures, BigInteger amount, long nrgPrice, - AionAddress to) { + Address to) { - int len = - 1 - + (AionAddress.SIZE * 2) - + (signatures.size() * SIG_LEN) - + AMOUNT_LEN - + Long.BYTES; + int len = 1 + (Address.SIZE * 2) + (signatures.size() * SIG_LEN) + AMOUNT_LEN + Long.BYTES; byte[] input = new byte[len]; int index = 0; input[index] = (byte) 0x1; index++; - System.arraycopy(wallet.toBytes(), 0, input, index, AionAddress.SIZE); - index += AionAddress.SIZE; + System.arraycopy(wallet.toBytes(), 0, input, index, Address.SIZE); + index += Address.SIZE; for (ISignature sig : signatures) { byte[] sigBytes = sig.toBytes(); @@ -150,7 +146,7 @@ public static byte[] constructSendTxInput( System.arraycopy(nrg, 0, input, index, Long.BYTES); index += Long.BYTES; - System.arraycopy(to.toBytes(), 0, input, index, AionAddress.SIZE); + System.arraycopy(to.toBytes(), 0, input, index, Address.SIZE); return input; } @@ -170,21 +166,13 @@ public static byte[] constructSendTxInput( * @return the transaction message that was signed. */ public static byte[] constructMsg( - AionAddress walletId, - BigInteger nonce, - AionAddress to, - BigInteger amount, - long nrgPrice) { + Address walletId, BigInteger nonce, Address to, BigInteger amount, long nrgPrice) { byte[] nonceBytes = nonce.toByteArray(); byte[] toBytes = to.toBytes(); byte[] amountBytes = amount.toByteArray(); int len = - AionAddress.SIZE - + nonceBytes.length - + toBytes.length - + amountBytes.length - + Long.BYTES; + Address.SIZE + nonceBytes.length + toBytes.length + amountBytes.length + Long.BYTES; byte[] msg = new byte[len]; ByteBuffer buffer = ByteBuffer.allocate(len); @@ -273,7 +261,7 @@ private PrecompiledTransactionResult createWallet(byte[] input, long nrg) { thresh.put(Arrays.copyOfRange(input, 1, 1 + Long.BYTES)); thresh.flip(); long threshold = thresh.getLong(); - Set owners = + Set
owners = extractAddresses(Arrays.copyOfRange(input, 1 + Long.BYTES, input.length)); if (!isValidTxNrg(nrg)) { @@ -290,9 +278,10 @@ private PrecompiledTransactionResult createWallet(byte[] input, long nrg) { return new PrecompiledTransactionResult(PrecompiledResultCode.FAILURE, 0); } - AionAddress wallet = initNewWallet(owners, threshold); + Address wallet = initNewWallet(owners, threshold); track.flush(); - return new PrecompiledTransactionResult(PrecompiledResultCode.SUCCESS, nrg - COST, wallet.toBytes()); + return new PrecompiledTransactionResult( + PrecompiledResultCode.SUCCESS, nrg - COST, wallet.toBytes()); } /** @@ -319,10 +308,10 @@ private PrecompiledTransactionResult sendTransaction(byte[] input, long nrg) { return new PrecompiledTransactionResult(PrecompiledResultCode.FAILURE, 0); } - AionAddress wallet = new AionAddress(Arrays.copyOfRange(input, walletStart, sigsStart)); + Address wallet = new AionAddress(Arrays.copyOfRange(input, walletStart, sigsStart)); List sigs = extractSignatures(Arrays.copyOfRange(input, sigsStart, amountStart)); BigInteger amount = new BigInteger(Arrays.copyOfRange(input, amountStart, nrgStart)); - AionAddress recipient = new AionAddress(Arrays.copyOfRange(input, recipientStart, length)); + Address recipient = new AionAddress(Arrays.copyOfRange(input, recipientStart, length)); ByteBuffer buffer = ByteBuffer.allocate(Long.BYTES); buffer.put(Arrays.copyOfRange(input, nrgStart, recipientStart)); @@ -373,7 +362,7 @@ private PrecompiledTransactionResult sendTransaction(byte[] input, long nrg) { * @param addresses A byte array of consecutive addresses. * @return The addresses extracted from the byte array. */ - private Set extractAddresses(byte[] addresses) { + private Set
extractAddresses(byte[] addresses) { int length = addresses.length; int numAddrs = length / ADDR_LEN; @@ -381,8 +370,8 @@ private Set extractAddresses(byte[] addresses) { return null; } - Set result = new HashSet<>(numAddrs); - AionAddress addr; + Set
result = new HashSet<>(numAddrs); + Address addr; boolean addressIsOwner = false; for (int i = 0; i < length; i += ADDR_LEN) { addr = new AionAddress(Arrays.copyOfRange(addresses, i, i + ADDR_LEN)); @@ -438,10 +427,10 @@ private List extractSignatures(byte[] signatures) { * @param threshold The minimum number of signatures required per transaction. * @return the address of the newly created wallet. */ - private AionAddress initNewWallet(Set owners, long threshold) { + private Address initNewWallet(Set
owners, long threshold) { List ownerAddrs = new ArrayList<>(); List ownerNonces = new ArrayList<>(); - for (AionAddress owner : owners) { + for (Address owner : owners) { ownerAddrs.add(owner.toBytes()); ownerNonces.add(track.getNonce(owner).toByteArray()); } @@ -465,7 +454,7 @@ private AionAddress initNewWallet(Set owners, long threshold) { byte[] hash = HashUtil.keccak256(content); hash[0] = AION_PREFIX; - AionAddress walletId = new AionAddress(hash); + Address walletId = new AionAddress(hash); track.createAccount(walletId); saveWalletMetaData(walletId, threshold, owners.size()); saveWalletOwners(walletId, owners); @@ -487,7 +476,7 @@ private AionAddress initNewWallet(Set owners, long threshold) { * @param threshold The minimum number of signatures required. * @param numOwners The number of owners for this wallet. */ - private void saveWalletMetaData(AionAddress walletId, long threshold, long numOwners) { + private void saveWalletMetaData(Address walletId, long threshold, long numOwners) { byte[] metaKey = getMetaDataKey(); byte[] metaValue = new byte[DataWord.BYTES]; @@ -517,11 +506,11 @@ private void saveWalletMetaData(AionAddress walletId, long threshold, long numOw * @param walletId The address of the multi-sig wallet. * @param owners The owners of the multi-sig wallet. */ - private void saveWalletOwners(AionAddress walletId, Set owners) { + private void saveWalletOwners(Address walletId, Set
owners) { byte[] firstKey, firstValue, secondKey, secondValue; long count = 0; - for (AionAddress owner : owners) { + for (Address owner : owners) { firstKey = getOwnerDataKey(true, count); secondKey = getOwnerDataKey(false, count); @@ -557,14 +546,14 @@ private void saveWalletOwners(AionAddress walletId, Set owners) { * @param msg The byte array form of the transaction that each signee had to sign. * @return true only if the signatures are valid for this wallet. */ - private boolean areValidSignatures(AionAddress wallet, List signatures, byte[] msg) { - Set owners = getOwners(wallet); + private boolean areValidSignatures(Address wallet, List signatures, byte[] msg) { + Set
owners = getOwners(wallet); if (!owners.contains(this.caller)) { return false; } - Set txSigners = new HashSet<>(); - AionAddress signer; + Set
txSigners = new HashSet<>(); + Address signer; for (byte[] sig : signatures) { if (!signatureIsCorrect(sig, msg)) { return false; @@ -610,8 +599,8 @@ private boolean signatureIsCorrect(byte[] signature, byte[] msg) { * @param walletId The address of the multi-sig wallet. * @return the set of owners. */ - private Set getOwners(AionAddress walletId) { - Set owners = new HashSet<>(); + private Set
getOwners(Address walletId) { + Set
owners = new HashSet<>(); ByteArrayWrapper metaValue = track.getStorageValue(walletId, new DataWord(getMetaDataKey()).toWrapper()); @@ -637,7 +626,7 @@ private Set getOwners(AionAddress walletId) { * @param ownerId The owner id. * @return the address of the owner. */ - private AionAddress getOwner(AionAddress walletId, long ownerId) { + private Address getOwner(Address walletId, long ownerId) { byte[] address = new byte[ADDR_LEN]; byte[] ownerDataKey1 = getOwnerDataKey(true, ownerId); diff --git a/modPrecompiled/src/org/aion/precompiled/contracts/TRS/AbstractTRS.java b/modPrecompiled/src/org/aion/precompiled/contracts/TRS/AbstractTRS.java index c696fd20a8..542ba7020a 100644 --- a/modPrecompiled/src/org/aion/precompiled/contracts/TRS/AbstractTRS.java +++ b/modPrecompiled/src/org/aion/precompiled/contracts/TRS/AbstractTRS.java @@ -17,6 +17,7 @@ import org.aion.mcf.vm.types.DoubleDataWord; import org.aion.precompiled.PrecompiledTransactionResult; import org.aion.precompiled.type.StatefulPrecompiledContract; +import org.aion.vm.api.interfaces.Address; /** * The purpose of this abstract class is mostly as a place to store important constants and methods @@ -24,14 +25,14 @@ */ public abstract class AbstractTRS extends StatefulPrecompiledContract { // TODO: grab AION from CfgAion later and preferably aion prefix too. - static final AionAddress AION = + static final Address AION = AionAddress.wrap("0xa0eeaeabdbc92953b072afbd21f3e3fd8a4a4f5e6a6e22200db746ab75e9a99a"); static final long COST = 21000L; // temporary. private static final long TEST_DURATION = 1; private static final long PERIOD_DURATION = TimeUnit.DAYS.toSeconds(30); static final byte AION_PREFIX = (byte) 0xA0; static final byte TRS_PREFIX = (byte) 0xC0; - final AionAddress caller; + final Address caller; protected final IBlockchain blockchain; /* @@ -101,7 +102,7 @@ public abstract class AbstractTRS extends StatefulPrecompiledContract { // Constructor. AbstractTRS( IRepositoryCache> track, - AionAddress caller, + Address caller, IBlockchain blockchain) { super(track); if (caller == null) { @@ -132,7 +133,7 @@ public abstract class AbstractTRS extends StatefulPrecompiledContract { * @param contract The TRS contract address to query. * @return the contract specifications or null if not a TRS contract. */ - public byte[] getContractSpecs(AionAddress contract) { + public byte[] getContractSpecs(Address contract) { if (contract.toBytes()[0] != TRS_PREFIX) { return null; } @@ -160,7 +161,7 @@ public byte[] getContractSpecs(AionAddress contract) { * @param precision the number of decimal places to left-shift percent. */ void setContractSpecs( - AionAddress contract, + Address contract, boolean isTest, boolean isDirectDeposit, int periods, @@ -193,7 +194,7 @@ void setContractSpecs( * @param contract The TRS contract address to query. * @return the owner of the contract or null if not a TRS contract. */ - public AionAddress getContractOwner(AionAddress contract) { + public Address getContractOwner(Address contract) { ByteArrayWrapper owner = track.getStorageValue(contract, OWNER_KEY); return (owner == null) ? null : new AionAddress(owner.getData()); } @@ -208,7 +209,7 @@ public AionAddress getContractOwner(AionAddress contract) { * * @param contract The TRS contract to update. */ - void setContractOwner(AionAddress contract) { + void setContractOwner(Address contract) { if (track.getStorageValue(contract, OWNER_KEY) != null) { return; } @@ -229,7 +230,7 @@ void setContractOwner(AionAddress contract) { * @return a byte array if there is a non-null head or null otherwise. * @throws NullPointerException if contract has no linked list. */ - public byte[] getListHead(AionAddress contract) { + public byte[] getListHead(Address contract) { ByteArrayWrapper head = track.getStorageValue(contract, LIST_HEAD_KEY); if (head == null) { throw new NullPointerException("Contract has no list: " + contract); @@ -255,7 +256,7 @@ public byte[] getListHead(AionAddress contract) { * @param contract The TRS contract to update. * @param head The head entry data to add. */ - void setListHead(AionAddress contract, byte[] head) { + void setListHead(Address contract, byte[] head) { if (head == null) { track.addStorageRow(contract, LIST_HEAD_KEY, NULL32); } else if (head.length == DOUBLE_WORD_SIZE) { @@ -278,7 +279,7 @@ void setListHead(AionAddress contract, byte[] head) { * @return a byte array if there is a non-null head or null otherwise. * @throws NullPointerException if contract has no linked list. */ - public byte[] getListPrev(AionAddress contract, AionAddress account) { + public byte[] getListPrev(Address contract, Address account) { byte[] prevKey = new byte[DOUBLE_WORD_SIZE]; prevKey[0] = LIST_PREV_PREFIX; System.arraycopy(account.toBytes(), 1, prevKey, 1, DOUBLE_WORD_SIZE - 1); @@ -311,7 +312,7 @@ public byte[] getListPrev(AionAddress contract, AionAddress account) { * @param account The account in contract whose previous entry is being updated. * @param prev The previous entry. */ - void setListPrevious(AionAddress contract, AionAddress account, byte[] prev) { + void setListPrevious(Address contract, Address account, byte[] prev) { setListPrevious(contract, account.toBytes(), prev); } @@ -333,7 +334,7 @@ void setListPrevious(AionAddress contract, AionAddress account, byte[] prev) { * @param account The account in contract whose previous entry is being updated. * @param prev The previous entry. */ - void setListPrevious(AionAddress contract, byte[] account, byte[] prev) { + void setListPrevious(Address contract, byte[] account, byte[] prev) { byte[] prevKey = new byte[DOUBLE_WORD_SIZE]; prevKey[0] = LIST_PREV_PREFIX; System.arraycopy(account, 1, prevKey, 1, DOUBLE_WORD_SIZE - 1); @@ -361,7 +362,7 @@ void setListPrevious(AionAddress contract, byte[] account, byte[] prev) { * @return account's next entry. * @throws NullPointerException if account has no next entry. */ - public byte[] getListNext(AionAddress contract, AionAddress account) { + public byte[] getListNext(Address contract, Address account) { return getListNext(contract, account.toBytes()); } @@ -380,7 +381,7 @@ public byte[] getListNext(AionAddress contract, AionAddress account) { * @return account's next entry. * @throws NullPointerException if account has no next entry. */ - byte[] getListNext(AionAddress contract, byte[] account) { + byte[] getListNext(Address contract, byte[] account) { ByteArrayWrapper next = track.getStorageValue(contract, toByteArrayWrapper(account)); if (next == null) { throw new NullPointerException("Account has no next: " + ByteUtil.toHexString(account)); @@ -408,7 +409,7 @@ byte[] getListNext(AionAddress contract, byte[] account) { * @return account's next entry. * @throws NullPointerException if account has no next entry. */ - public byte[] getListNextBytes(AionAddress contract, AionAddress account) { + public byte[] getListNextBytes(Address contract, Address account) { ByteArrayWrapper next = track.getStorageValue(contract, toByteArrayWrapper(account.toBytes())); if (next == null) { @@ -445,7 +446,7 @@ public byte[] getListNextBytes(AionAddress contract, AionAddress account) { * @param isValid True only if the account is to be marked as invalid or deleted. */ void setListNext( - AionAddress contract, AionAddress account, byte oldMeta, byte[] next, boolean isValid) { + Address contract, Address account, byte oldMeta, byte[] next, boolean isValid) { setListNext(contract, account.toBytes(), oldMeta, next, isValid); } @@ -476,8 +477,7 @@ void setListNext( * @param next The next entry. * @param isValid True only if the account is to be marked as invalid or deleted. */ - void setListNext( - AionAddress contract, byte[] account, byte oldMeta, byte[] next, boolean isValid) { + void setListNext(Address contract, byte[] account, byte oldMeta, byte[] next, boolean isValid) { if (!isValid) { // Mark account invalid and also make it ineligible for special withdrawal. track.addStorageRow(contract, toByteArrayWrapper(account), INVALID); @@ -516,7 +516,7 @@ public static boolean accountIsValid(byte[] spec) { * @param contract The TRS contract to query. * @return the total balance of the contract. */ - public BigInteger getTotalBalance(AionAddress contract) { + public BigInteger getTotalBalance(Address contract) { ByteArrayWrapper ttlSpec = track.getStorageValue(contract, FUNDS_SPECS_KEY); int numRows = ByteBuffer.wrap( @@ -555,7 +555,7 @@ public BigInteger getTotalBalance(AionAddress contract) { * @param balance The total balance to set. * @throws IllegalArgumentException if balance is negative. */ - void setTotalBalance(AionAddress contract, BigInteger balance) { + void setTotalBalance(Address contract, BigInteger balance) { if (balance.compareTo(BigInteger.ZERO) < 0) { throw new IllegalArgumentException("setTotalBalance to negative balance!"); } @@ -586,7 +586,7 @@ void setTotalBalance(AionAddress contract, BigInteger balance) { * @param account The account to look up. * @return the account's deposit balance for this TRS contract. */ - public BigInteger getDepositBalance(AionAddress contract, AionAddress account) { + public BigInteger getDepositBalance(Address contract, Address account) { ByteArrayWrapper accountData = track.getStorageValue(contract, toByteArrayWrapper(account.toBytes())); if (accountData == null) { @@ -627,7 +627,7 @@ public BigInteger getDepositBalance(AionAddress contract, AionAddress account) { * @param account The account to update. * @param balance The deposit balance to set. */ - boolean setDepositBalance(AionAddress contract, AionAddress account, BigInteger balance) { + boolean setDepositBalance(Address contract, Address account, BigInteger balance) { if (balance.compareTo(BigInteger.ONE) < 0) { return true; } @@ -672,7 +672,7 @@ boolean setDepositBalance(AionAddress contract, AionAddress account, BigInteger * * @param contract The address of the TRS contract. */ - void setLock(AionAddress contract) { + void setLock(Address contract) { byte[] spec = getContractSpecs(contract); spec[LOCK_OFFSET] = (byte) 0x1; track.addStorageRow(contract, SPECS_KEY, toByteArrayWrapper(spec)); @@ -686,7 +686,7 @@ void setLock(AionAddress contract) { * * @param contract The address of the TRS contract. */ - void setLive(AionAddress contract) { + void setLive(Address contract) { byte[] spec = getContractSpecs(contract); spec[LIVE_OFFSET] = (byte) 0x1; track.addStorageRow(contract, SPECS_KEY, toByteArrayWrapper(spec)); @@ -735,7 +735,7 @@ public static int getPeriods(byte[] specs) { * @param contract The TRS contract to update. * @param timestamp The timestamp value to set. */ - public void setTimestamp(AionAddress contract, long timestamp) { + public void setTimestamp(Address contract, long timestamp) { if (track.getStorageValue(contract, TIMESTAMP) != null) { return; } @@ -757,7 +757,7 @@ public void setTimestamp(AionAddress contract, long timestamp) { * @param contract The TRS contract to query. * @return The timestamp for the TRS contract contract. */ - public long getTimestamp(AionAddress contract) { + public long getTimestamp(Address contract) { ByteArrayWrapper value = track.getStorageValue(contract, TIMESTAMP); if (value == null) { return -1; @@ -809,7 +809,7 @@ public long getTimestamp(AionAddress contract) { * @param account The account to withdraw funds from. * @return true only if a non-zero amount was withdrawn from the contract into account. */ - boolean makeWithdrawal(AionAddress contract, AionAddress account) { + boolean makeWithdrawal(Address contract, Address account) { byte[] specs = getContractSpecs(contract); if (specs == null) { return false; @@ -877,7 +877,7 @@ boolean makeWithdrawal(AionAddress contract, AionAddress account) { * @param contract The TRS contract to update. * @param account The account whose withdrawal stats will be initialized. */ - private void initWithdrawalStats(AionAddress contract, AionAddress account) { + private void initWithdrawalStats(Address contract, Address account) { byte[] stats = new byte[SINGLE_WORD_SIZE]; stats[0] = 0x1; // set is-eligible. stats[SINGLE_WORD_SIZE - 1] = 0x0; // sanity. Set is-done to false (is done withdrawing) @@ -896,7 +896,7 @@ private void initWithdrawalStats(AionAddress contract, AionAddress account) { * @param contract The TRS contract to update. * @param account The account to update. */ - private void setAccountIsDoneWithdrawing(AionAddress contract, AionAddress account) { + private void setAccountIsDoneWithdrawing(Address contract, Address account) { ByteArrayWrapper stats = track.getStorageValue(contract, toByteArrayWrapper(makeWithdrawalKey(account))); if (stats == null) { @@ -922,7 +922,7 @@ private void setAccountIsDoneWithdrawing(AionAddress contract, AionAddress accou * @param account The account to query. * @return true only if account is done withdrawing funds from contract. */ - public boolean isAccountDoneWithdrawing(AionAddress contract, AionAddress account) { + public boolean isAccountDoneWithdrawing(Address contract, Address account) { ByteArrayWrapper stats = track.getStorageValue(contract, toByteArrayWrapper(makeWithdrawalKey(account))); if (stats == null) { @@ -943,7 +943,7 @@ public boolean isAccountDoneWithdrawing(AionAddress contract, AionAddress accoun * @param contract The TRS contract to update. * @param account The account to be made ineligible for the special withdrawal. */ - private void setAccountIneligibleForSpecial(AionAddress contract, byte[] account) { + private void setAccountIneligibleForSpecial(Address contract, byte[] account) { ByteArrayWrapper stats = track.getStorageValue(contract, toByteArrayWrapper(makeWithdrawalKey(account))); byte[] statsBytes = (stats == null) ? new byte[SINGLE_WORD_SIZE] : stats.getData(); @@ -964,8 +964,7 @@ private void setAccountIneligibleForSpecial(AionAddress contract, byte[] account * @param account The account whose most recent period is to be updated. * @throws NullPointerException if account has no withdrawal stats. */ - private void updateAccountLastWithdrawalPeriod( - AionAddress contract, AionAddress account, int period) { + private void updateAccountLastWithdrawalPeriod(Address contract, Address account, int period) { ByteArrayWrapper stats = track.getStorageValue(contract, toByteArrayWrapper(makeWithdrawalKey(account))); if (stats == null) { @@ -991,7 +990,7 @@ private void updateAccountLastWithdrawalPeriod( * @param account The account to query. * @return the last period in which account has withdrawn from the contract. */ - public int getAccountLastWithdrawalPeriod(AionAddress contract, AionAddress account) { + public int getAccountLastWithdrawalPeriod(Address contract, Address account) { ByteArrayWrapper stats = track.getStorageValue(contract, toByteArrayWrapper(makeWithdrawalKey(account))); if ((stats == null) || (!accountIsValid(getListNextBytes(contract, account)))) { @@ -1014,7 +1013,7 @@ public int getAccountLastWithdrawalPeriod(AionAddress contract, AionAddress acco * @param account The account whose special withdrawal eligibility is to be queried. * @return true only if the account is eligible for the special withdrawal event. */ - public boolean accountIsEligibleForSpecial(AionAddress contract, AionAddress account) { + public boolean accountIsEligibleForSpecial(Address contract, Address account) { ByteArrayWrapper stats = track.getStorageValue(contract, toByteArrayWrapper(makeWithdrawalKey(account))); return ((stats != null) && (stats.getData()[0] == 0x1)); @@ -1035,7 +1034,7 @@ public boolean accountIsEligibleForSpecial(AionAddress contract, AionAddress acc * @param account The account to query. * @return the amount of tokens account is eligible to withdraw in special one-off event. */ - private BigInteger computeSpecialWithdrawalAmount(AionAddress contract, AionAddress account) { + private BigInteger computeSpecialWithdrawalAmount(Address contract, Address account) { if (accountIsEligibleForSpecial(contract, account)) { return computeRawSpecialAmount(contract, account); } else { @@ -1052,7 +1051,7 @@ private BigInteger computeSpecialWithdrawalAmount(AionAddress contract, AionAddr * @param account The account to query. * @return the amount account is eligible to withdraw in the special event. */ - BigInteger computeRawSpecialAmount(AionAddress contract, AionAddress account) { + BigInteger computeRawSpecialAmount(Address contract, Address account) { BigDecimal owed = new BigDecimal(computeTotalOwed(contract, account)); BigDecimal percent = getPercentage(getContractSpecs(contract)).movePointLeft(2); return owed.multiply(percent).toBigInteger(); @@ -1069,8 +1068,7 @@ BigInteger computeRawSpecialAmount(AionAddress contract, AionAddress account) { * @param currPeriod The current period the contract is in. * @return the number of withdrawal periods account is behind currPeriod by. */ - private int computeNumberPeriodsBehind( - AionAddress contract, AionAddress account, int currPeriod) { + private int computeNumberPeriodsBehind(Address contract, Address account, int currPeriod) { return currPeriod - getAccountLastWithdrawalPeriod(contract, account); } @@ -1092,7 +1090,7 @@ private int computeNumberPeriodsBehind( * @return the amount of funds account is eligible to withdraw each period, excluding special * funds. */ - BigInteger computeAmountWithdrawPerPeriod(AionAddress contract, AionAddress account) { + BigInteger computeAmountWithdrawPerPeriod(Address contract, Address account) { BigDecimal owedWithoutSpecial = new BigDecimal( computeTotalOwed(contract, account) @@ -1113,7 +1111,7 @@ BigInteger computeAmountWithdrawPerPeriod(AionAddress contract, AionAddress acco * @param account The account to query. * @return the total amount of funds owed to account over the lifetime of the contract. */ - public BigInteger computeTotalOwed(AionAddress contract, AionAddress account) { + public BigInteger computeTotalOwed(Address contract, Address account) { return getDepositBalance(contract, account).add(computeBonusShare(contract, account)); } @@ -1130,7 +1128,7 @@ public BigInteger computeTotalOwed(AionAddress contract, AionAddress account) { * @return the share of bonus tokens account is entitled to receive. * @throws IllegalStateException if contract has no total balance. */ - public BigInteger computeBonusShare(AionAddress contract, AionAddress account) { + public BigInteger computeBonusShare(Address contract, Address account) { BigDecimal bonusFunds = new BigDecimal(getBonusBalance(contract)); BigDecimal fraction = getDepositorFraction(contract, account); BigDecimal share = fraction.multiply(bonusFunds); @@ -1145,7 +1143,7 @@ public BigInteger computeBonusShare(AionAddress contract, AionAddress account) { * @param account The account. * @return the fraction of the total deposits account owns. */ - private BigDecimal getDepositorFraction(AionAddress contract, AionAddress account) { + private BigDecimal getDepositorFraction(Address contract, Address account) { BigDecimal acctBalance = new BigDecimal(getDepositBalance(contract, account)); BigInteger totalBalance = getTotalBalance(contract); if (totalBalance.compareTo(BigInteger.ZERO) <= 0) { @@ -1166,7 +1164,7 @@ private BigDecimal getDepositorFraction(AionAddress contract, AionAddress accoun * @param account The account to query. * @return the amount of unclaimed tokens account has yet to withdraw from their total owings. */ - private BigInteger computeOutstadingOwings(AionAddress contract, AionAddress account) { + private BigInteger computeOutstadingOwings(Address contract, Address account) { int lastPeriod = getAccountLastWithdrawalPeriod(contract, account); BigInteger amtPerPeriod = computeAmountWithdrawPerPeriod(contract, account); BigInteger specialAmt = computeRawSpecialAmount(contract, account); @@ -1207,7 +1205,7 @@ private BigInteger computeOutstadingOwings(AionAddress contract, AionAddress acc * @return the extra funds account is able to withdraw. */ public BigInteger computeExtraFundsToWithdraw( - AionAddress contract, AionAddress account, BigDecimal fraction, int currPeriod) { + Address contract, Address account, BigDecimal fraction, int currPeriod) { BigInteger share = fraction.multiply(new BigDecimal(getExtraFunds(contract))).toBigInteger(); @@ -1239,7 +1237,7 @@ public BigInteger computeExtraFundsToWithdraw( * @param contract The TRS contract to update. * @throws IllegalStateException if contract has no balance. */ - void setBonusBalance(AionAddress contract) { + void setBonusBalance(Address contract) { if (track.getStorageValue(contract, BONUS_SPECS_KEY) != null) { return; } @@ -1273,7 +1271,7 @@ void setBonusBalance(AionAddress contract) { * @param contract The TRS contract to query. * @return the bonus balance of the TRS contract contract. */ - public BigInteger getBonusBalance(AionAddress contract) { + public BigInteger getBonusBalance(Address contract) { ByteArrayWrapper bonusSpec = track.getStorageValue(contract, BONUS_SPECS_KEY); if (bonusSpec == null) { return BigInteger.ZERO; @@ -1309,7 +1307,7 @@ public BigInteger getBonusBalance(AionAddress contract) { * @param contract The TRS contract to update. * @param account The account to update. */ - private void initExtraWithdrawalSpecs(AionAddress contract, AionAddress account) { + private void initExtraWithdrawalSpecs(Address contract, Address account) { byte[] specs = new byte[SINGLE_WORD_SIZE]; specs[0] = 0x0; track.addStorageRow( @@ -1329,7 +1327,7 @@ private void initExtraWithdrawalSpecs(AionAddress contract, AionAddress account) * @param account The account to query. * @return the extra funds account has already withdrawn from contract. */ - public BigInteger getExtraWithdrawalBalance(AionAddress contract, AionAddress account) { + public BigInteger getExtraWithdrawalBalance(Address contract, Address account) { ByteArrayWrapper extraSpecs = track.getStorageValue(contract, toByteArrayWrapper(makeExtraSpecsKey(account))); if (extraSpecs == null) { @@ -1356,8 +1354,7 @@ public BigInteger getExtraWithdrawalBalance(AionAddress contract, AionAddress ac * @param contract The TRS contract to update. * @param account The TRS account to update. */ - private void setExtraWithdrawalBalance( - AionAddress contract, AionAddress account, BigInteger amount) { + private void setExtraWithdrawalBalance(Address contract, Address account, BigInteger amount) { if (amount.compareTo(BigInteger.ONE) < 0) { return; } @@ -1389,7 +1386,7 @@ private void setExtraWithdrawalBalance( * @param contract The TRS contract to query. * @return the amount of extra funds contract has. */ - public BigInteger getExtraFunds(AionAddress contract) { + public BigInteger getExtraFunds(Address contract) { ByteArrayWrapper extraSpecs = track.getStorageValue(contract, EXTRA_SPECS_KEY); if (extraSpecs == null) { return BigInteger.ZERO; @@ -1425,7 +1422,7 @@ public BigInteger getExtraFunds(AionAddress contract) { * @param contract The TRS contract to update. * @param amount The amount of extra funds contract will now have. */ - void setExtraFunds(AionAddress contract, BigInteger amount) { + void setExtraFunds(Address contract, BigInteger amount) { if (amount.compareTo(BigInteger.ONE) < 0) { return; } @@ -1454,7 +1451,7 @@ void setExtraFunds(AionAddress contract, BigInteger amount) { * Initializes the open funds data so that the is-open-funds bit is not set. If an open funds * entry in the database already exists then this method does nothing. */ - void initOpenFunds(AionAddress contract) { + void initOpenFunds(Address contract) { if (track.getStorageValue(contract, OPEN_KEY) != null) { return; } @@ -1477,7 +1474,7 @@ void initOpenFunds(AionAddress contract) { *

If contract does not exist this method throws an exception for debugging. This should * never happen. */ - void setIsOpenFunds(AionAddress contract) { + void setIsOpenFunds(Address contract) { ByteArrayWrapper value = track.getStorageValue(contract, OPEN_KEY); if (value == null) { throw new IllegalStateException( @@ -1493,7 +1490,7 @@ void setIsOpenFunds(AionAddress contract) { * * @return true only if the contract's funds are open and the contract has been killed. */ - public boolean isOpenFunds(AionAddress contract) { + public boolean isOpenFunds(Address contract) { ByteArrayWrapper value = track.getStorageValue(contract, OPEN_KEY); return ((value != null) && (value.getData()[0] == 0x1)); } @@ -1518,7 +1515,7 @@ public boolean isOpenFunds(AionAddress contract) { * @param currTime The time at which the contract is being queried for. * @return the period the contract is in at currTime. */ - public int calculatePeriod(AionAddress contract, byte[] specs, long currTime) { + public int calculatePeriod(Address contract, byte[] specs, long currTime) { long timestamp = getTimestamp(contract); if (timestamp > currTime) { return 0; @@ -1538,7 +1535,7 @@ public int calculatePeriod(AionAddress contract, byte[] specs, long currTime) { * @param contract The TRS contract to query. * @return true if contract is locked. */ - public boolean isContractLocked(AionAddress contract) { + public boolean isContractLocked(Address contract) { if (isOpenFunds(contract)) { return false; } @@ -1552,7 +1549,7 @@ public boolean isContractLocked(AionAddress contract) { * @param contract The TRS contract to query. * @return true if contract is live. */ - public boolean isContractLive(AionAddress contract) { + public boolean isContractLive(Address contract) { if (isOpenFunds(contract)) { return false; } @@ -1566,7 +1563,7 @@ public boolean isContractLive(AionAddress contract) { * @param contract The TRS contract to query. * @return true only if direct deposits are enabled. */ - public boolean isDirDepositsEnabled(AionAddress contract) { + public boolean isDirDepositsEnabled(Address contract) { if (isOpenFunds(contract)) { return false; } @@ -1625,10 +1622,10 @@ private byte[] makeExtraKey(int row) { * @param account The account whose withdrawal specs this key is for. * @return the key to access the specified withdrawal specifications entry. */ - private byte[] makeExtraSpecsKey(AionAddress account) { + private byte[] makeExtraSpecsKey(Address account) { byte[] extraSpecKey = new byte[DOUBLE_WORD_SIZE]; extraSpecKey[0] = EXTRA_WITH_SPEC_PREFIX; - System.arraycopy(account.toBytes(), 1, extraSpecKey, 1, AionAddress.SIZE - 1); + System.arraycopy(account.toBytes(), 1, extraSpecKey, 1, Address.SIZE - 1); return extraSpecKey; } @@ -1640,11 +1637,11 @@ private byte[] makeExtraSpecsKey(AionAddress account) { * @param row The row of the extras-withdrawn amount this key is for. * @return the key to access the specified extras-withdrawn entry. */ - private byte[] makeExtraWithdrawnKey(AionAddress account, int row) { + private byte[] makeExtraWithdrawnKey(Address account, int row) { byte[] extraWithKey = new byte[DOUBLE_WORD_SIZE]; extraWithKey[0] = EXTRA_WITH_PREFIX; extraWithKey[0] |= (row & 0x0F); - System.arraycopy(account.toBytes(), 1, extraWithKey, 1, AionAddress.SIZE - 1); + System.arraycopy(account.toBytes(), 1, extraWithKey, 1, Address.SIZE - 1); return extraWithKey; } @@ -1672,7 +1669,7 @@ private byte[] makeTotalBalanceKey(int row) { * @param row The balance row to query. * @return the key to access the specified balance row for the account in contract. */ - private byte[] makeBalanceKey(AionAddress account, int row) { + private byte[] makeBalanceKey(Address account, int row) { if (account == null) { return DataWord.ZERO.getData(); } @@ -1690,7 +1687,7 @@ private byte[] makeBalanceKey(AionAddress account, int row) { * @param account The account to look up. * @return the key to access the account's withdrawal stats. */ - private byte[] makeWithdrawalKey(AionAddress account) { + private byte[] makeWithdrawalKey(Address account) { if (account == null) { return DataWord.ZERO.getData(); } diff --git a/modPrecompiled/src/org/aion/precompiled/contracts/TRS/PrivateTRScontract.java b/modPrecompiled/src/org/aion/precompiled/contracts/TRS/PrivateTRScontract.java index e9526ad4f1..db5e28873d 100644 --- a/modPrecompiled/src/org/aion/precompiled/contracts/TRS/PrivateTRScontract.java +++ b/modPrecompiled/src/org/aion/precompiled/contracts/TRS/PrivateTRScontract.java @@ -1,11 +1,11 @@ package org.aion.precompiled.contracts.TRS; import org.aion.base.db.IRepositoryCache; -import org.aion.base.type.AionAddress; import org.aion.mcf.core.AccountState; import org.aion.mcf.db.IBlockStoreBase; import org.aion.precompiled.PrecompiledTransactionResult; import org.aion.precompiled.type.StatefulPrecompiledContract; +import org.aion.vm.api.interfaces.Address; /** * The PrivateTRScontract is a private version of the TRS contract that is used solely by The Aion @@ -20,7 +20,7 @@ * in that the latter calls this contract to perform any supported operations it needs. */ public final class PrivateTRScontract extends StatefulPrecompiledContract { - private final AionAddress caller; + private final Address caller; /** * Constructs a new PrivateTRScontract that will use repo as the database cache to update its @@ -30,7 +30,7 @@ public final class PrivateTRScontract extends StatefulPrecompiledContract { * @param caller The calling address. */ public PrivateTRScontract( - IRepositoryCache> repo, AionAddress caller) { + IRepositoryCache> repo, Address caller) { super(repo); this.caller = caller; diff --git a/modPrecompiled/src/org/aion/precompiled/contracts/TRS/TRSqueryContract.java b/modPrecompiled/src/org/aion/precompiled/contracts/TRS/TRSqueryContract.java index 7d57ff0d3f..095aca79c6 100644 --- a/modPrecompiled/src/org/aion/precompiled/contracts/TRS/TRSqueryContract.java +++ b/modPrecompiled/src/org/aion/precompiled/contracts/TRS/TRSqueryContract.java @@ -13,6 +13,7 @@ import org.aion.mcf.db.IBlockStoreBase; import org.aion.precompiled.PrecompiledResultCode; import org.aion.precompiled.PrecompiledTransactionResult; +import org.aion.vm.api.interfaces.Address; /** * The TRSqueryContract is 1 of 3 inter-dependent but separate contracts that together make up the @@ -48,7 +49,7 @@ public final class TRSqueryContract extends AbstractTRS { */ public TRSqueryContract( IRepositoryCache> repo, - AionAddress caller, + Address caller, IBlockchain blockchain) { super(repo, caller, blockchain); @@ -213,7 +214,7 @@ private PrecompiledTransactionResult isStarted(byte[] input, long nrgLimit) { } byte[] result = new byte[1]; - AionAddress contract = AionAddress.wrap(Arrays.copyOfRange(input, indexAddress, len)); + Address contract = AionAddress.wrap(Arrays.copyOfRange(input, indexAddress, len)); if (!isOpenFunds(contract) && isContractLive(contract)) { result[0] = 0x1; } @@ -246,7 +247,7 @@ private PrecompiledTransactionResult isLocked(byte[] input, long nrgLimit) { } byte[] result = new byte[1]; - AionAddress contract = AionAddress.wrap(Arrays.copyOfRange(input, indexAddress, len)); + Address contract = AionAddress.wrap(Arrays.copyOfRange(input, indexAddress, len)); if (!isOpenFunds(contract) && isContractLocked(contract)) { result[0] = 0x1; } @@ -280,7 +281,7 @@ private PrecompiledTransactionResult isDirectDepositEnabled(byte[] input, long n } byte[] result = new byte[1]; - AionAddress contract = AionAddress.wrap(Arrays.copyOfRange(input, indexAddress, len)); + Address contract = AionAddress.wrap(Arrays.copyOfRange(input, indexAddress, len)); if (!isOpenFunds(contract) && isDirDepositsEnabled(contract)) { result[0] = 0x1; } @@ -321,7 +322,7 @@ private PrecompiledTransactionResult period(byte[] input, long nrgLimit) { } // Grab the contract address and block number and determine the period. - AionAddress contract = AionAddress.wrap(Arrays.copyOfRange(input, indexAddress, len)); + Address contract = AionAddress.wrap(Arrays.copyOfRange(input, indexAddress, len)); return determinePeriod(contract, blockchain.getBestBlock(), nrgLimit); } @@ -359,8 +360,7 @@ private PrecompiledTransactionResult periodAt(byte[] input, long nrgLimit) { } // Grab the contract address and block number and determine the period. - AionAddress contract = - AionAddress.wrap(Arrays.copyOfRange(input, indexAddress, indexBlockNum)); + Address contract = AionAddress.wrap(Arrays.copyOfRange(input, indexAddress, indexBlockNum)); ByteBuffer blockBuf = ByteBuffer.allocate(Long.BYTES); blockBuf.put(Arrays.copyOfRange(input, indexBlockNum, len)); @@ -404,7 +404,7 @@ private PrecompiledTransactionResult availableForWithdrawalAt(byte[] input, long return new PrecompiledTransactionResult(PrecompiledResultCode.FAILURE, 0); } - AionAddress contract = + Address contract = AionAddress.wrap(Arrays.copyOfRange(input, indexContract, indexTimestamp)); byte[] specs = getContractSpecs(contract); if (specs == null) { @@ -478,8 +478,7 @@ private PrecompiledTransactionResult availableForWithdrawalAt(byte[] input, long * @param nrg The energy. * @return the period the contract is in at time given by block's timestamp. */ - private PrecompiledTransactionResult determinePeriod( - AionAddress contract, IBlock block, long nrg) { + private PrecompiledTransactionResult determinePeriod(Address contract, IBlock block, long nrg) { // If contract doesn't exist, return an error. ByteBuffer output = ByteBuffer.allocate(Integer.BYTES); diff --git a/modPrecompiled/src/org/aion/precompiled/contracts/TRS/TRSstateContract.java b/modPrecompiled/src/org/aion/precompiled/contracts/TRS/TRSstateContract.java index 90a8cc03a1..bcbb3c11bc 100644 --- a/modPrecompiled/src/org/aion/precompiled/contracts/TRS/TRSstateContract.java +++ b/modPrecompiled/src/org/aion/precompiled/contracts/TRS/TRSstateContract.java @@ -12,6 +12,7 @@ import org.aion.mcf.db.IBlockStoreBase; import org.aion.precompiled.PrecompiledResultCode; import org.aion.precompiled.PrecompiledTransactionResult; +import org.aion.vm.api.interfaces.Address; /** * The TRSstateContract is 1 of 3 inter-dependent but separate contracts that together make up the @@ -45,7 +46,7 @@ public final class TRSstateContract extends AbstractTRS { */ public TRSstateContract( IRepositoryCache> track, - AionAddress caller, + Address caller, IBlockchain blockchain) { super(track, caller, blockchain); @@ -233,12 +234,12 @@ private PrecompiledTransactionResult create(byte[] input, long nrgLimit) { // All checks OK. Generate contract address, save the new contract & return to caller. byte[] ownerNonce = track.getNonce(caller).toByteArray(); - byte[] hashInfo = new byte[ownerNonce.length + AionAddress.SIZE]; + byte[] hashInfo = new byte[ownerNonce.length + Address.SIZE]; System.arraycopy(ownerNonce, 0, hashInfo, 0, ownerNonce.length); - System.arraycopy(caller.toBytes(), 0, hashInfo, ownerNonce.length, AionAddress.SIZE); + System.arraycopy(caller.toBytes(), 0, hashInfo, ownerNonce.length, Address.SIZE); byte[] trsAddr = HashUtil.h256(hashInfo); trsAddr[0] = TRS_PREFIX; - AionAddress contract = new AionAddress(trsAddr); + Address contract = new AionAddress(trsAddr); saveNewContract(contract, isTestContract, isDirectDeposit, periods, percent, precision); return new PrecompiledTransactionResult( @@ -272,8 +273,8 @@ private PrecompiledTransactionResult lock(byte[] input, long nrgLimit) { } // The caller must also be the owner of this contract. - AionAddress contract = - new AionAddress(Arrays.copyOfRange(input, indexAddr, indexAddr + AionAddress.SIZE)); + Address contract = + new AionAddress(Arrays.copyOfRange(input, indexAddr, indexAddr + Address.SIZE)); if (!caller.equals(getContractOwner(contract))) { return new PrecompiledTransactionResult(PrecompiledResultCode.FAILURE, 0); } @@ -327,8 +328,8 @@ private PrecompiledTransactionResult start(byte[] input, long nrgLimit) { } // The caller must also be the owner of this contract. - AionAddress contract = - new AionAddress(Arrays.copyOfRange(input, indexAddr, indexAddr + AionAddress.SIZE)); + Address contract = + new AionAddress(Arrays.copyOfRange(input, indexAddr, indexAddr + Address.SIZE)); if (!caller.equals(getContractOwner(contract))) { return new PrecompiledTransactionResult(PrecompiledResultCode.FAILURE, 0); } @@ -378,7 +379,7 @@ private PrecompiledTransactionResult openFunds(byte[] input, long nrgLimit) { return new PrecompiledTransactionResult(PrecompiledResultCode.FAILURE, 0); } - AionAddress contract = AionAddress.wrap(Arrays.copyOfRange(input, indexContract, len)); + Address contract = AionAddress.wrap(Arrays.copyOfRange(input, indexContract, len)); byte[] specs = getContractSpecs(contract); if (specs == null) { return new PrecompiledTransactionResult(PrecompiledResultCode.FAILURE, 0); @@ -431,7 +432,7 @@ private PrecompiledTransactionResult openFunds(byte[] input, long nrgLimit) { * @param precision The number of decimal places to put the decimal point in percent. */ private void saveNewContract( - AionAddress contract, + Address contract, boolean isTest, boolean isDirectDeposit, int periods, diff --git a/modPrecompiled/src/org/aion/precompiled/contracts/TRS/TRSuseContract.java b/modPrecompiled/src/org/aion/precompiled/contracts/TRS/TRSuseContract.java index 9d6c8bed8c..28b2506c11 100644 --- a/modPrecompiled/src/org/aion/precompiled/contracts/TRS/TRSuseContract.java +++ b/modPrecompiled/src/org/aion/precompiled/contracts/TRS/TRSuseContract.java @@ -9,6 +9,7 @@ import org.aion.mcf.db.IBlockStoreBase; import org.aion.precompiled.PrecompiledResultCode; import org.aion.precompiled.PrecompiledTransactionResult; +import org.aion.vm.api.interfaces.Address; /** * The TRSuseContract is 1 of 3 inter-dependent but separate contracts that together make up the @@ -45,7 +46,7 @@ public final class TRSuseContract extends AbstractTRS { */ public TRSuseContract( IRepositoryCache> repo, - AionAddress caller, + Address caller, IBlockchain blockchain) { super(repo, caller, blockchain); @@ -252,15 +253,14 @@ private PrecompiledTransactionResult deposit(byte[] input, long nrgLimit) { return new PrecompiledTransactionResult(PrecompiledResultCode.FAILURE, 0); } - AionAddress contract = - AionAddress.wrap(Arrays.copyOfRange(input, indexAddress, indexAmount)); + Address contract = AionAddress.wrap(Arrays.copyOfRange(input, indexAddress, indexAmount)); byte[] specs = getContractSpecs(contract); if (specs == null) { return new PrecompiledTransactionResult(PrecompiledResultCode.FAILURE, 0); } // A deposit operation can only execute if direct depositing is enabled or caller is owner. - AionAddress owner = getContractOwner(contract); + Address owner = getContractOwner(contract); if (!caller.equals(owner) && !isDirDepositsEnabled(contract)) { return new PrecompiledTransactionResult(PrecompiledResultCode.FAILURE, 0); } @@ -314,7 +314,7 @@ private PrecompiledTransactionResult withdraw(byte[] input, long nrgLimit) { return new PrecompiledTransactionResult(PrecompiledResultCode.FAILURE, 0); } - AionAddress contract = AionAddress.wrap(Arrays.copyOfRange(input, indexAddress, len)); + Address contract = AionAddress.wrap(Arrays.copyOfRange(input, indexAddress, len)); byte[] specs = getContractSpecs(contract); if (specs == null) { return new PrecompiledTransactionResult(PrecompiledResultCode.FAILURE, 0); @@ -362,7 +362,7 @@ private PrecompiledTransactionResult bulkDepositFor(byte[] input, long nrgLimit) final int indexContract = 1; final int indexEntries = 33; final int entryLen = 160; - final int entryAddrLen = AionAddress.SIZE; + final int entryAddrLen = Address.SIZE; final int maxEntries = 100; // First ensure some basic properties about input hold: its lower and upper size limits and @@ -374,8 +374,7 @@ private PrecompiledTransactionResult bulkDepositFor(byte[] input, long nrgLimit) return new PrecompiledTransactionResult(PrecompiledResultCode.FAILURE, 0); } - AionAddress contract = - AionAddress.wrap(Arrays.copyOfRange(input, indexContract, indexEntries)); + Address contract = AionAddress.wrap(Arrays.copyOfRange(input, indexContract, indexEntries)); byte[] specs = getContractSpecs(contract); if (specs == null) { return new PrecompiledTransactionResult(PrecompiledResultCode.FAILURE, 0); @@ -398,7 +397,7 @@ private PrecompiledTransactionResult bulkDepositFor(byte[] input, long nrgLimit) int amtLen = entryLen - entryAddrLen; int index = indexEntries; byte[] amountBytes; - AionAddress[] beneficiaries = new AionAddress[numEntries]; + Address[] beneficiaries = new AionAddress[numEntries]; BigInteger[] amounts = new BigInteger[numEntries]; for (int i = 0; i < numEntries; i++) { // Put amount in a byte array one byte larger with an empty initial byte so it is @@ -459,7 +458,7 @@ private PrecompiledTransactionResult bulkWithdraw(byte[] input, long nrgLimit) { return new PrecompiledTransactionResult(PrecompiledResultCode.FAILURE, 0); } - AionAddress contract = AionAddress.wrap(Arrays.copyOfRange(input, indexAddress, len)); + Address contract = AionAddress.wrap(Arrays.copyOfRange(input, indexAddress, len)); byte[] specs = getContractSpecs(contract); if (specs == null) { return new PrecompiledTransactionResult(PrecompiledResultCode.FAILURE, 0); @@ -484,7 +483,7 @@ private PrecompiledTransactionResult bulkWithdraw(byte[] input, long nrgLimit) { while (curr != null) { curr[0] = AION_PREFIX; - AionAddress currAcct = new AionAddress(curr); + Address currAcct = new AionAddress(curr); makeWithdrawal(contract, currAcct); curr = getListNext(contract, currAcct); } @@ -525,15 +524,14 @@ private PrecompiledTransactionResult refund(byte[] input, long nrgLimit) { return new PrecompiledTransactionResult(PrecompiledResultCode.FAILURE, 0); } - AionAddress contract = - AionAddress.wrap(Arrays.copyOfRange(input, indexContract, indexAccount)); + Address contract = AionAddress.wrap(Arrays.copyOfRange(input, indexContract, indexAccount)); byte[] specs = getContractSpecs(contract); if (specs == null) { return new PrecompiledTransactionResult(PrecompiledResultCode.FAILURE, 0); } // A refund operation can only execute if the caller is the contract owner. - AionAddress owner = getContractOwner(contract); + Address owner = getContractOwner(contract); if (!caller.equals(owner)) { return new PrecompiledTransactionResult(PrecompiledResultCode.FAILURE, 0); } @@ -546,8 +544,7 @@ private PrecompiledTransactionResult refund(byte[] input, long nrgLimit) { } // Ensure the account exists (ie. has a positive deposit balance for the contract). - AionAddress account = - AionAddress.wrap(Arrays.copyOfRange(input, indexAccount, indexAmount)); + Address account = AionAddress.wrap(Arrays.copyOfRange(input, indexAccount, indexAmount)); BigInteger accountBalance = getDepositBalance(contract, account); if (accountBalance.equals(BigInteger.ZERO)) { return new PrecompiledTransactionResult(PrecompiledResultCode.FAILURE, 0); @@ -614,8 +611,7 @@ private PrecompiledTransactionResult depositFor(byte[] input, long nrgLimit) { return new PrecompiledTransactionResult(PrecompiledResultCode.FAILURE, 0); } - AionAddress contract = - AionAddress.wrap(Arrays.copyOfRange(input, indexContract, indexAccount)); + Address contract = AionAddress.wrap(Arrays.copyOfRange(input, indexContract, indexAccount)); byte[] specs = getContractSpecs(contract); if (specs == null) { return new PrecompiledTransactionResult(PrecompiledResultCode.FAILURE, 0); @@ -649,8 +645,7 @@ private PrecompiledTransactionResult depositFor(byte[] input, long nrgLimit) { return new PrecompiledTransactionResult(PrecompiledResultCode.FAILURE, 0); } - AionAddress account = - AionAddress.wrap(Arrays.copyOfRange(input, indexAccount, indexAmount)); + Address account = AionAddress.wrap(Arrays.copyOfRange(input, indexAccount, indexAmount)); PrecompiledTransactionResult result = makeDeposit(contract, account, amount, nrgLimit); if (result.getResultCode().equals(PrecompiledResultCode.SUCCESS)) { track.flush(); @@ -684,8 +679,7 @@ private PrecompiledTransactionResult addExtraFunds(byte[] input, long nrgLimit) return new PrecompiledTransactionResult(PrecompiledResultCode.FAILURE, 0); } - AionAddress contract = - AionAddress.wrap(Arrays.copyOfRange(input, indexContract, indexAmount)); + Address contract = AionAddress.wrap(Arrays.copyOfRange(input, indexContract, indexAmount)); byte[] specs = getContractSpecs(contract); if (specs == null) { return new PrecompiledTransactionResult(PrecompiledResultCode.FAILURE, 0); @@ -740,7 +734,7 @@ private PrecompiledTransactionResult addExtraFunds(byte[] input, long nrgLimit) * @return an execution result of either success or internal error. */ private PrecompiledTransactionResult makeDeposit( - AionAddress contract, AionAddress account, BigInteger amount, long nrgLimit) { + Address contract, Address account, BigInteger amount, long nrgLimit) { // If deposit amount is larger than zero, update the curret deposit balance of the account // for which this deposit is on the behalf of, and update the meta-deta etc. @@ -768,7 +762,7 @@ private PrecompiledTransactionResult makeDeposit( * * @param contract The TRS contract to update. */ - private void listAddCallerToHead(AionAddress contract) { + private void listAddCallerToHead(Address contract) { listAddToHead(contract, caller); } @@ -784,7 +778,7 @@ private void listAddCallerToHead(AionAddress contract) { * * @param contract The TRS contract to update. */ - private void listAddToHead(AionAddress contract, AionAddress account) { + private void listAddToHead(Address contract, Address account) { byte[] next = getListNextBytes(contract, account); if (accountIsValid(next)) { return; @@ -800,11 +794,11 @@ private void listAddToHead(AionAddress contract, AionAddress account) { setListPrevious( contract, AionAddress.wrap(head), - Arrays.copyOf(account.toBytes(), AionAddress.SIZE)); + Arrays.copyOf(account.toBytes(), Address.SIZE)); } // Set the head of the list to point to account and set account's previous entry to null. - setListHead(contract, Arrays.copyOf(account.toBytes(), AionAddress.SIZE)); + setListHead(contract, Arrays.copyOf(account.toBytes(), Address.SIZE)); setListPrevious(contract, account, null); } @@ -822,7 +816,7 @@ private void listAddToHead(AionAddress contract, AionAddress account) { * @param contract The TRS contract to update. * @param account The account to remove from the list. */ - private void listRemoveAccount(AionAddress contract, AionAddress account) { + private void listRemoveAccount(Address contract, Address account) { byte[] prev = getListPrev(contract, account); byte[] next = getListNext(contract, account); diff --git a/modPrecompiled/test/org/aion/precompiled/TRS/TRShelpers.java b/modPrecompiled/test/org/aion/precompiled/TRS/TRShelpers.java index 2751313046..fbec4ef720 100644 --- a/modPrecompiled/test/org/aion/precompiled/TRS/TRShelpers.java +++ b/modPrecompiled/test/org/aion/precompiled/TRS/TRShelpers.java @@ -30,6 +30,7 @@ import org.aion.precompiled.contracts.TRS.TRSqueryContract; import org.aion.precompiled.contracts.TRS.TRSstateContract; import org.aion.precompiled.contracts.TRS.TRSuseContract; +import org.aion.vm.api.interfaces.Address; import org.aion.zero.impl.StandaloneBlockchain; import org.aion.zero.impl.core.IAionBlockchain; import org.aion.zero.impl.types.AionBlock; @@ -40,16 +41,16 @@ class TRShelpers { private static final byte[] OUT = new byte[1]; static final BigInteger DEFAULT_BALANCE = BigInteger.TEN; private IAionBlockchain blockchain = StandaloneBlockchain.inst(); - AionAddress AION = + Address AION = AionAddress.wrap("0xa0eeaeabdbc92953b072afbd21f3e3fd8a4a4f5e6a6e22200db746ab75e9a99a"); IRepositoryCache> repo; - List tempAddrs; + List

tempAddrs; ECKey senderKey; long COST = 21000L; // Returns a new account with initial balance balance that exists in the repo. - AionAddress getNewExistentAccount(BigInteger balance) { - AionAddress acct = AionAddress.wrap(ECKeyFac.inst().create().getAddress()); + Address getNewExistentAccount(BigInteger balance) { + Address acct = AionAddress.wrap(ECKeyFac.inst().create().getAddress()); acct.toBytes()[0] = (byte) 0xA0; repo.createAccount(acct); repo.addBalance(acct, balance); @@ -59,23 +60,23 @@ AionAddress getNewExistentAccount(BigInteger balance) { } // Returns a new TRSstateContract that calls the contract using caller. - TRSstateContract newTRSstateContract(AionAddress caller) { + TRSstateContract newTRSstateContract(Address caller) { return new TRSstateContract(repo, caller, blockchain); } // Returns a new TRSuseContract that calls the contract using caller. - TRSuseContract newTRSuseContract(AionAddress caller) { + TRSuseContract newTRSuseContract(Address caller) { return new TRSuseContract(repo, caller, blockchain); } // Returns a new TRSqueryContract that calls the contract using caller. - TRSqueryContract newTRSqueryContract(AionAddress caller) { + TRSqueryContract newTRSqueryContract(Address caller) { return new TRSqueryContract(repo, caller, blockchain); } // Returns the address of a newly created TRS contract, assumes all params are valid. - AionAddress createTRScontract( - AionAddress owner, + Address createTRScontract( + Address owner, boolean isTest, boolean isDirectDeposit, int periods, @@ -88,7 +89,7 @@ AionAddress createTRScontract( if (!res.getResultCode().equals(PrecompiledResultCode.SUCCESS)) { fail("Unable to create contract!"); } - AionAddress contract = new AionAddress(res.getOutput()); + Address contract = new AionAddress(res.getOutput()); tempAddrs.add(contract); repo.incrementNonce(owner); repo.flush(); @@ -97,15 +98,15 @@ AionAddress createTRScontract( // Returns the address of a newly created TRS contract and locks it; assumes all params valid. // The owner deposits 1 token so that the contract can be locked. - AionAddress createAndLockTRScontract( - AionAddress owner, + Address createAndLockTRScontract( + Address owner, boolean isTest, boolean isDirectDeposit, int periods, BigInteger percent, int precision) { - AionAddress contract = + Address contract = createTRScontract(owner, isTest, isDirectDeposit, periods, percent, precision); byte[] input = getDepositInput(contract, BigInteger.ONE); if (!newTRSuseContract(owner) @@ -129,15 +130,15 @@ AionAddress createAndLockTRScontract( // Returns the address of a newly created TRS contract that is locked and live. The owner // deposits // token so that the contract can be locked. - AionAddress createLockedAndLiveTRScontract( - AionAddress owner, + Address createLockedAndLiveTRScontract( + Address owner, boolean isTest, boolean isDirectDeposit, int periods, BigInteger percent, int precision) { - AionAddress contract = + Address contract = createTRScontract(owner, isTest, isDirectDeposit, periods, percent, precision); byte[] input = getDepositInput(contract, BigInteger.ONE); if (!newTRSuseContract(owner) @@ -166,7 +167,7 @@ AionAddress createLockedAndLiveTRScontract( } // Locks and makes contract live, where owner is owner of the contract. - void lockAndStartContract(AionAddress contract, AionAddress owner) { + void lockAndStartContract(Address contract, Address owner) { byte[] input = getLockInput(contract); AbstractTRS trs = newTRSstateContract(owner); if (!trs.execute(input, COST).getResultCode().equals(PrecompiledResultCode.SUCCESS)) { @@ -181,20 +182,20 @@ void lockAndStartContract(AionAddress contract, AionAddress owner) { // Returns a TRS contract address that has numDepositors depositors in it (owner does not // deposit) // each with DEFAULT_BALANCE deposit balance. - AionAddress getContractMultipleDepositors( + Address getContractMultipleDepositors( int numDepositors, - AionAddress owner, + Address owner, boolean isTest, boolean isDirectDeposit, int periods, BigInteger percent, int precision) { - AionAddress contract = + Address contract = createTRScontract(owner, isTest, isDirectDeposit, periods, percent, precision); byte[] input = getDepositInput(contract, DEFAULT_BALANCE); for (int i = 0; i < numDepositors; i++) { - AionAddress acct = getNewExistentAccount(DEFAULT_BALANCE); + Address acct = getNewExistentAccount(DEFAULT_BALANCE); if (!newTRSuseContract(acct) .execute(input, COST) .getResultCode() @@ -208,18 +209,18 @@ AionAddress getContractMultipleDepositors( // Returns a TRS contract address that has numDepositors depositors in it (owner does not // deposit) // each with DEFAULT_BALANCE deposit balance. Owner uses depositFor to deposit for depositors. - AionAddress getContractMultipleDepositorsUsingDepositFor( + Address getContractMultipleDepositorsUsingDepositFor( int numDepositors, - AionAddress owner, + Address owner, boolean isTest, int periods, BigInteger percent, int precision) { - AionAddress contract = createTRScontract(owner, isTest, false, periods, percent, precision); + Address contract = createTRScontract(owner, isTest, false, periods, percent, precision); AbstractTRS trs = newTRSuseContract(owner); for (int i = 0; i < numDepositors; i++) { - AionAddress acct = getNewExistentAccount(BigInteger.ZERO); + Address acct = getNewExistentAccount(BigInteger.ZERO); byte[] input = getDepositForInput(contract, acct, DEFAULT_BALANCE); if (!trs.execute(input, COST).getResultCode().equals(PrecompiledResultCode.SUCCESS)) { Assert.fail("Depositor #" + i + " failed to deposit!"); @@ -254,49 +255,49 @@ void mockBlockchainBlock(long blockNum, long timestamp) { } // Returns the amount of extra funds that the TRS contract contract has. - BigInteger getExtraFunds(AbstractTRS trs, AionAddress contract) { + BigInteger getExtraFunds(AbstractTRS trs, Address contract) { return trs.getExtraFunds(contract); } // Returns the period the contract is in at the block number blockNum. - BigInteger getPeriodAt(AbstractTRS trs, AionAddress contract, long blockNum) { + BigInteger getPeriodAt(AbstractTRS trs, Address contract, long blockNum) { long timestamp = blockchain.getBlockByNumber(blockNum).getTimestamp(); return BigInteger.valueOf( trs.calculatePeriod(contract, getContractSpecs(trs, contract), timestamp)); } // Returns the percentage configured for the TRS contract. - BigDecimal getPercentage(AbstractTRS trs, AionAddress contract) { + BigDecimal getPercentage(AbstractTRS trs, Address contract) { return AbstractTRS.getPercentage(trs.getContractSpecs(contract)); } // Returns the periods configured for the TRS contract. - int getPeriods(AbstractTRS trs, AionAddress contract) { + int getPeriods(AbstractTRS trs, Address contract) { return AbstractTRS.getPeriods(trs.getContractSpecs(contract)); } // Returns the deposit balance of account in the TRS contract contract. - BigInteger getDepositBalance(AbstractTRS trs, AionAddress contract, AionAddress account) { + BigInteger getDepositBalance(AbstractTRS trs, Address contract, Address account) { return trs.getDepositBalance(contract, account); } // Returns the balance of bonus tokens in the TRS contract contract. - BigInteger getBonusBalance(AbstractTRS trs, AionAddress contract) { + BigInteger getBonusBalance(AbstractTRS trs, Address contract) { return trs.getBonusBalance(contract); } // Returns true only if the TRS contract has its funds open. - boolean getAreContractFundsOpen(AbstractTRS trs, AionAddress contract) { + boolean getAreContractFundsOpen(AbstractTRS trs, Address contract) { return trs.isOpenFunds(contract); } // Returns the total deposit balance for the TRS contract contract. - BigInteger getTotalBalance(AbstractTRS trs, AionAddress contract) { + BigInteger getTotalBalance(AbstractTRS trs, Address contract) { return trs.getTotalBalance(contract); } // Returns true only if account is a valid account in contract. - boolean accountIsValid(AbstractTRS trs, AionAddress contract, AionAddress account) { + boolean accountIsValid(AbstractTRS trs, Address contract, Address account) { try { return AbstractTRS.accountIsValid(trs.getListNextBytes(contract, account)); } catch (Exception e) { @@ -306,63 +307,62 @@ boolean accountIsValid(AbstractTRS trs, AionAddress contract, AionAddress accoun } // Returns the address of the owner of the TRS contract given by the address contract. - AionAddress getOwner(AbstractTRS trs, AionAddress contract) { + Address getOwner(AbstractTRS trs, Address contract) { return trs.getContractOwner(contract); } // Returns true only if the TRS contract is in Test Mode. - boolean isTestContract(AbstractTRS trs, AionAddress contract) { + boolean isTestContract(AbstractTRS trs, Address contract) { return AbstractTRS.isTestContract(trs.getContractSpecs(contract)); } // Returns true only if the TRS contract has direct deposit enabled. - boolean isDirectDepositEnabled(AbstractTRS trs, AionAddress contract) { + boolean isDirectDepositEnabled(AbstractTRS trs, Address contract) { return trs.isDirDepositsEnabled(contract); } // Returns true only if the TRS contract whose contract specs are given by specsData is locked. - boolean isContractLocked(AbstractTRS trs, AionAddress contract) { + boolean isContractLocked(AbstractTRS trs, Address contract) { return trs.isContractLocked(contract); } // Returns true only if the TRS contract whose contract specs are given by specsData is live. - boolean isContractLive(AbstractTRS trs, AionAddress contract) { + boolean isContractLive(AbstractTRS trs, Address contract) { return trs.isContractLive(contract); } // Returns the timestamp for this contract. - long getContractTimestamp(AbstractTRS trs, AionAddress contract) { + long getContractTimestamp(AbstractTRS trs, Address contract) { return trs.getTimestamp(contract); } // Returns true only if account is eligible to use the special one-off withdrawal event. - boolean accountIsEligibleForSpecial( - TRSuseContract trs, AionAddress contract, AionAddress account) { + boolean accountIsEligibleForSpecial(TRSuseContract trs, Address contract, Address account) { return trs.accountIsEligibleForSpecial(contract, account); } // Returns the last period in which account made a withdrawal or -1 if bad contract or account. - int getAccountLastWithdrawalPeriod(AbstractTRS trs, AionAddress contract, AionAddress account) { + int getAccountLastWithdrawalPeriod(AbstractTRS trs, Address contract, Address account) { return trs.getAccountLastWithdrawalPeriod(contract, account); } // Returns the share of the bonus tokens account is entitled to withdraw over life of contract. - BigInteger getBonusShare(AbstractTRS trs, AionAddress contract, AionAddress account) { + BigInteger getBonusShare(AbstractTRS trs, Address contract, Address account) { return trs.computeBonusShare(contract, account); } // Returns the amount of extras account is able to withdraw in the current period. BigInteger getExtraShare( AbstractTRS trs, - AionAddress contract, - AionAddress account, + Address contract, + Address account, BigDecimal fraction, int currPeriod) { return trs.computeExtraFundsToWithdraw(contract, account, fraction, currPeriod); } // Grabs the current period contract is in as a BigInteger. - BigInteger getCurrentPeriod(AbstractTRS trs, AionAddress contract) { + BigInteger getCurrentPeriod(AbstractTRS trs, Address contract) { return BigInteger.valueOf(getContractCurrentPeriod(trs, contract)); } @@ -387,7 +387,7 @@ BigInteger getWithdrawAmt(BigInteger owings, BigInteger specialAmt, int periods) } // Returns the period that contract is currently in. - int getContractCurrentPeriod(AbstractTRS trs, AionAddress contract) { + int getContractCurrentPeriod(AbstractTRS trs, Address contract) { long currTime = blockchain.getBestBlock().getTimestamp(); return trs.calculatePeriod(contract, trs.getContractSpecs(contract), currTime); } @@ -400,7 +400,7 @@ BigInteger grabOwings(BigDecimal accBalance, BigDecimal contractBalance, BigDeci } // Returns the total amount of tokens account can withdraw over the lifetime of the contract. - BigInteger getTotalOwed(AbstractTRS trs, AionAddress contract, AionAddress account) { + BigInteger getTotalOwed(AbstractTRS trs, Address contract, Address account) { return trs.computeTotalOwed(contract, account); } @@ -425,7 +425,7 @@ BigInteger getTotalOwed(AbstractTRS trs, AionAddress contract, AionAddress accou */ BigInteger expectedAmtFirstWithdraw( AbstractTRS trs, - AionAddress contract, + Address contract, BigInteger deposits, BigInteger total, BigInteger bonus, @@ -463,7 +463,7 @@ BigInteger expectedAmtFirstWithdraw( * @param percentage The percent of total owings that can be claimed in special event. * @return the address of the contract. */ - AionAddress setupContract( + Address setupContract( int numDepositors, BigInteger deposits, BigInteger bonus, @@ -472,14 +472,14 @@ AionAddress setupContract( int precision = percentage.scale(); BigInteger percent = percentage.movePointRight(precision).toBigInteger(); - AionAddress contract = createTRScontract(AION, true, true, periods, percent, precision); + Address contract = createTRScontract(AION, true, true, periods, percent, precision); assertEquals(percentage, getPercentage(newTRSstateContract(AION), contract)); assertEquals(periods, getPeriods(newTRSstateContract(AION), contract)); byte[] input = getDepositInput(contract, deposits); for (int i = 0; i < numDepositors; i++) { - AionAddress acc = getNewExistentAccount(deposits); + Address acc = getNewExistentAccount(deposits); assertEquals( PrecompiledResultCode.SUCCESS, newTRSuseContract(acc).execute(input, COST).getResultCode()); @@ -517,106 +517,106 @@ byte[] getCreateInput( } // Returns an input byte array for the lock operation using the provided parameters. - byte[] getLockInput(AionAddress contract) { + byte[] getLockInput(Address contract) { byte[] input = new byte[33]; input[0] = (byte) 0x1; - System.arraycopy(contract.toBytes(), 0, input, 1, AionAddress.SIZE); + System.arraycopy(contract.toBytes(), 0, input, 1, Address.SIZE); return input; } // Returns an input byte array for the start operation using the provided parameters. - byte[] getStartInput(AionAddress contract) { + byte[] getStartInput(Address contract) { byte[] input = new byte[33]; input[0] = (byte) 0x2; - System.arraycopy(contract.toBytes(), 0, input, 1, AionAddress.SIZE); + System.arraycopy(contract.toBytes(), 0, input, 1, Address.SIZE); return input; } // Returns a properly formatted byte array to be used as input for the deposit operation. - byte[] getDepositInput(AionAddress contract, BigInteger amount) { + byte[] getDepositInput(Address contract, BigInteger amount) { byte[] amtBytes = amount.toByteArray(); if (amtBytes.length > 128) { fail(); } byte[] input = new byte[161]; input[0] = 0x0; - System.arraycopy(contract.toBytes(), 0, input, 1, AionAddress.SIZE); + System.arraycopy(contract.toBytes(), 0, input, 1, Address.SIZE); System.arraycopy(amtBytes, 0, input, 161 - amtBytes.length, amtBytes.length); return input; } // Returns a properly formatted byte array to be used as input for the deposit-for operation. - byte[] getDepositForInput(AionAddress contract, AionAddress beneficiary, BigInteger amount) { + byte[] getDepositForInput(Address contract, Address beneficiary, BigInteger amount) { byte[] amtBytes = amount.toByteArray(); if (amtBytes.length > 128) { fail(); } byte[] input = new byte[193]; input[0] = 0x5; - System.arraycopy(contract.toBytes(), 0, input, 1, AionAddress.SIZE); - System.arraycopy(beneficiary.toBytes(), 0, input, 33, AionAddress.SIZE); + System.arraycopy(contract.toBytes(), 0, input, 1, Address.SIZE); + System.arraycopy(beneficiary.toBytes(), 0, input, 33, Address.SIZE); System.arraycopy(amtBytes, 0, input, 193 - amtBytes.length, amtBytes.length); return input; } // Returns a properly formatted byte array to be used as input for the withdraw operation. - byte[] getWithdrawInput(AionAddress contract) { + byte[] getWithdrawInput(Address contract) { byte[] input = new byte[33]; input[0] = (byte) 0x1; - System.arraycopy(contract.toBytes(), 0, input, 1, AionAddress.SIZE); + System.arraycopy(contract.toBytes(), 0, input, 1, Address.SIZE); return input; } // Returns a properly formatted byte array to be used as input for the refund operation. - byte[] getRefundInput(AionAddress contract, AionAddress account, BigInteger amount) { + byte[] getRefundInput(Address contract, Address account, BigInteger amount) { byte[] amtBytes = amount.toByteArray(); if (amtBytes.length > 128) { Assert.fail(); } byte[] input = new byte[193]; input[0] = 0x4; - System.arraycopy(contract.toBytes(), 0, input, 1, AionAddress.SIZE); - System.arraycopy(account.toBytes(), 0, input, 33, AionAddress.SIZE); + System.arraycopy(contract.toBytes(), 0, input, 1, Address.SIZE); + System.arraycopy(account.toBytes(), 0, input, 33, Address.SIZE); System.arraycopy(amtBytes, 0, input, 193 - amtBytes.length, amtBytes.length); return input; } // Returns a properly formatted byte array to be used as input for the isLive (or isStarted) // operation. - byte[] getIsLiveInput(AionAddress contract) { + byte[] getIsLiveInput(Address contract) { byte[] input = new byte[33]; input[0] = 0x0; - System.arraycopy(contract.toBytes(), 0, input, 1, AionAddress.SIZE); + System.arraycopy(contract.toBytes(), 0, input, 1, Address.SIZE); return input; } // Returns a properly formatted byte array to be used as input for the isLocked operation. - byte[] getIsLockedInput(AionAddress contract) { + byte[] getIsLockedInput(Address contract) { byte[] input = new byte[33]; input[0] = 0x1; - System.arraycopy(contract.toBytes(), 0, input, 1, AionAddress.SIZE); + System.arraycopy(contract.toBytes(), 0, input, 1, Address.SIZE); return input; } // Returns a properly formatted byte array to be used as input for the isDirectDepositEnabled // op. - byte[] getIsDirDepoEnabledInput(AionAddress contract) { + byte[] getIsDirDepoEnabledInput(Address contract) { byte[] input = new byte[33]; input[0] = 0x2; - System.arraycopy(contract.toBytes(), 0, input, 1, AionAddress.SIZE); + System.arraycopy(contract.toBytes(), 0, input, 1, Address.SIZE); return input; } // Returns a properly formatted byte array to be used as input for the period operation. - byte[] getPeriodInput(AionAddress contract) { + byte[] getPeriodInput(Address contract) { byte[] input = new byte[33]; input[0] = 0x3; - System.arraycopy(contract.toBytes(), 0, input, 1, AionAddress.SIZE); + System.arraycopy(contract.toBytes(), 0, input, 1, Address.SIZE); return input; } // Returns a properly formatted byte array to be used as input for the periodsAt operation. - byte[] getPeriodAtInput(AionAddress contract, long blockNum) { + byte[] getPeriodAtInput(Address contract, long blockNum) { ByteBuffer buffer = ByteBuffer.allocate(41); buffer.put((byte) 0x4); buffer.put(contract.toBytes()); @@ -625,27 +625,27 @@ byte[] getPeriodAtInput(AionAddress contract, long blockNum) { } // Returns a properly formatted byte array to be used as input for the bulk-withdraw operation. - byte[] getBulkWithdrawInput(AionAddress contract) { + byte[] getBulkWithdrawInput(Address contract) { byte[] input = new byte[33]; input[0] = 0x3; - System.arraycopy(contract.toBytes(), 0, input, 1, AionAddress.SIZE); + System.arraycopy(contract.toBytes(), 0, input, 1, Address.SIZE); return input; } // Returns a properly formatted byte array to be used as input for the open-funds operation. - byte[] getOpenFundsInput(AionAddress contract) { + byte[] getOpenFundsInput(Address contract) { byte[] input = new byte[33]; input[0] = 0x3; - System.arraycopy(contract.toBytes(), 0, input, 1, AionAddress.SIZE); + System.arraycopy(contract.toBytes(), 0, input, 1, Address.SIZE); return input; } // Returns a properly formatted byte array to be used as input for the available-for-.. // operation. - byte[] getAvailableForWithdrawalAtInput(AionAddress contract, long timestamp) { + byte[] getAvailableForWithdrawalAtInput(Address contract, long timestamp) { byte[] input = new byte[41]; input[0] = 0x5; - System.arraycopy(contract.toBytes(), 0, input, 1, AionAddress.SIZE); + System.arraycopy(contract.toBytes(), 0, input, 1, Address.SIZE); ByteBuffer buffer = ByteBuffer.allocate(Long.BYTES); buffer.putLong(timestamp); byte[] buf = buffer.array(); @@ -654,10 +654,10 @@ byte[] getAvailableForWithdrawalAtInput(AionAddress contract, long timestamp) { } // Returns a properly formatted byte array to be used as input for the addExtraFunds operation. - byte[] getAddExtraInput(AionAddress contract, BigInteger amount) { + byte[] getAddExtraInput(Address contract, BigInteger amount) { byte[] input = new byte[161]; input[0] = 0x6; - System.arraycopy(contract.toBytes(), 0, input, 1, AionAddress.SIZE); + System.arraycopy(contract.toBytes(), 0, input, 1, Address.SIZE); byte[] amtBytes = amount.toByteArray(); if (amtBytes.length > 128) { fail(); @@ -667,10 +667,10 @@ byte[] getAddExtraInput(AionAddress contract, BigInteger amount) { } // Returns a properly formatted byte array to add the max extra funds in one operation. - byte[] getAddExtraMaxInput(AionAddress contract) { + byte[] getAddExtraMaxInput(Address contract) { byte[] input = new byte[161]; input[0] = 0x6; - System.arraycopy(contract.toBytes(), 0, input, 1, AionAddress.SIZE); + System.arraycopy(contract.toBytes(), 0, input, 1, Address.SIZE); for (int i = 33; i < 161; i++) { input[i] = (byte) 0xFF; } @@ -679,8 +679,7 @@ byte[] getAddExtraMaxInput(AionAddress contract) { // Returns a properly formatted byte array to bulk deposit for each account in beneficiaries. // This method does: deposit amounts[i] on behalf of beneficiaries[i] - byte[] getBulkDepositForInput( - AionAddress contract, AionAddress[] beneficiaries, BigInteger[] amounts) { + byte[] getBulkDepositForInput(Address contract, Address[] beneficiaries, BigInteger[] amounts) { int len = beneficiaries.length; if ((len < 1) || (len > 100)) { fail("Imporper length: " + len); @@ -692,10 +691,10 @@ byte[] getBulkDepositForInput( byte[] input = new byte[arrLen]; input[0] = 0x2; - System.arraycopy(contract.toBytes(), 0, input, 1, AionAddress.SIZE); + System.arraycopy(contract.toBytes(), 0, input, 1, Address.SIZE); int index = 33; for (int i = 0; i < len; i++) { - System.arraycopy(beneficiaries[i].toBytes(), 0, input, index, AionAddress.SIZE); + System.arraycopy(beneficiaries[i].toBytes(), 0, input, index, Address.SIZE); index += 32 + 128; byte[] amtBytes = amounts[i].toByteArray(); if (amtBytes.length > 128) { @@ -708,11 +707,11 @@ byte[] getBulkDepositForInput( // Returns a properly formatted byte array to be used as input for the refund operation, to // refund the maximum allowable amount. - byte[] getMaxRefundInput(AionAddress contract, AionAddress account) { + byte[] getMaxRefundInput(Address contract, Address account) { byte[] input = new byte[193]; input[0] = 0x4; - System.arraycopy(contract.toBytes(), 0, input, 1, AionAddress.SIZE); - System.arraycopy(account.toBytes(), 0, input, 33, AionAddress.SIZE); + System.arraycopy(contract.toBytes(), 0, input, 1, Address.SIZE); + System.arraycopy(account.toBytes(), 0, input, 33, Address.SIZE); for (int i = 65; i < 193; i++) { input[i] = (byte) 0xFF; } @@ -721,10 +720,10 @@ byte[] getMaxRefundInput(AionAddress contract, AionAddress account) { // Returns a properly formatted byte array to be used as input for the deposit operation, to // deposit the maximum allowable amount. - byte[] getMaxDepositInput(AionAddress contract) { + byte[] getMaxDepositInput(Address contract) { byte[] input = new byte[161]; input[0] = 0x0; - System.arraycopy(contract.toBytes(), 0, input, 1, AionAddress.SIZE); + System.arraycopy(contract.toBytes(), 0, input, 1, Address.SIZE); for (int i = 33; i < 161; i++) { input[i] = (byte) 0xFF; } @@ -732,9 +731,8 @@ byte[] getMaxDepositInput(AionAddress contract) { } // Makes input for numBeneficiaries beneficiaries who each receive a deposit amount deposits. - byte[] makeBulkDepositForInput( - AionAddress contract, int numBeneficiaries, BigInteger deposits) { - AionAddress[] beneficiaries = new AionAddress[numBeneficiaries]; + byte[] makeBulkDepositForInput(Address contract, int numBeneficiaries, BigInteger deposits) { + Address[] beneficiaries = new AionAddress[numBeneficiaries]; BigInteger[] amounts = new BigInteger[numBeneficiaries]; for (int i = 0; i < numBeneficiaries; i++) { beneficiaries[i] = getNewExistentAccount(BigInteger.ZERO); @@ -745,9 +743,9 @@ byte[] makeBulkDepositForInput( // Makes input for numOthers beneficiaries and self who each receive a deposit amount deposits. byte[] makeBulkDepositForInputwithSelf( - AionAddress contract, AionAddress self, int numOthers, BigInteger deposits) { + Address contract, Address self, int numOthers, BigInteger deposits) { - AionAddress[] beneficiaries = new AionAddress[numOthers + 1]; + Address[] beneficiaries = new AionAddress[numOthers + 1]; BigInteger[] amounts = new BigInteger[numOthers + 1]; for (int i = 0; i < numOthers; i++) { beneficiaries[i] = getNewExistentAccount(BigInteger.ZERO); @@ -765,9 +763,9 @@ byte[] makeBulkDepositForInputwithSelf( * @param contract The TRS contract to query. * @return the set of all depositors. */ - Set getAllDepositors(AbstractTRS trs, AionAddress contract) { - Set depositors = new HashSet<>(); - AionAddress curr = getLinkedListHead(trs, contract); + Set
getAllDepositors(AbstractTRS trs, Address contract) { + Set
depositors = new HashSet<>(); + Address curr = getLinkedListHead(trs, contract); while (curr != null) { assertFalse(depositors.contains(curr)); depositors.add(curr); @@ -777,7 +775,7 @@ Set getAllDepositors(AbstractTRS trs, AionAddress contract) { } // Returns the head of the list for contract or null if no head. - AionAddress getLinkedListHead(AbstractTRS trs, AionAddress contract) { + Address getLinkedListHead(AbstractTRS trs, Address contract) { byte[] head = trs.getListHead(contract); if (head == null) { return null; @@ -787,7 +785,7 @@ AionAddress getLinkedListHead(AbstractTRS trs, AionAddress contract) { } // Returns the next account in the linked list after current, or null if no next. - AionAddress getLinkedListNext(AbstractTRS trs, AionAddress contract, AionAddress current) { + Address getLinkedListNext(AbstractTRS trs, Address contract, Address current) { byte[] next = trs.getListNextBytes(contract, current); boolean noNext = (((next[0] & 0x80) == 0x80) || ((next[0] & 0x40) == 0x00)); if (noNext) { @@ -798,7 +796,7 @@ AionAddress getLinkedListNext(AbstractTRS trs, AionAddress contract, AionAddress } // Returns the previous account in the linked list prior to current, or null if no previous. - AionAddress getLinkedListPrev(AbstractTRS trs, AionAddress contract, AionAddress current) { + Address getLinkedListPrev(AbstractTRS trs, Address contract, Address current) { byte[] prev = trs.getListPrev(contract, current); if (prev == null) { return null; @@ -810,7 +808,7 @@ AionAddress getLinkedListPrev(AbstractTRS trs, AionAddress contract, AionAddress // Checks that each account is paid out correctly when they withdraw in a non-final period. void checkPayoutsNonFinal( AbstractTRS trs, - AionAddress contract, + Address contract, int numDepositors, BigInteger deposits, BigInteger bonus, @@ -818,12 +816,12 @@ void checkPayoutsNonFinal( int periods, int currPeriod) { - Set contributors = getAllDepositors(trs, contract); + Set
contributors = getAllDepositors(trs, contract); BigInteger total = deposits.multiply(BigInteger.valueOf(numDepositors)); BigDecimal fraction = BigDecimal.ONE.divide(new BigDecimal(numDepositors), 18, RoundingMode.HALF_DOWN); - for (AionAddress acc : contributors) { + for (Address acc : contributors) { BigInteger extraShare = getExtraShare(trs, contract, acc, fraction, currPeriod); BigInteger amt = expectedAmtFirstWithdraw( @@ -840,13 +838,13 @@ void checkPayoutsNonFinal( // Checks that each account is paid out correctly when they withdraw in a final period. void checkPayoutsFinal( AbstractTRS trs, - AionAddress contract, + Address contract, int numDepositors, BigInteger deposits, BigInteger bonus, BigInteger extra) { - Set contributors = getAllDepositors(trs, contract); + Set
contributors = getAllDepositors(trs, contract); BigDecimal fraction = BigDecimal.ONE.divide(new BigDecimal(numDepositors), 18, RoundingMode.HALF_DOWN); BigInteger extraShare = fraction.multiply(new BigDecimal(extra)).toBigInteger(); @@ -856,7 +854,7 @@ void checkPayoutsFinal( .toBigInteger(); BigInteger collected = amt.add(extraShare); - for (AionAddress acc : contributors) { + for (Address acc : contributors) { byte[] input = getWithdrawInput(contract); assertEquals( PrecompiledResultCode.SUCCESS, @@ -875,7 +873,7 @@ void checkPayoutsFinal( // Checks that availableForWithdrawalAt returns expected results for the specified query. void checkAvailableForResults( AbstractTRS trs, - AionAddress contract, + Address contract, long timestamp, int numDepositors, BigInteger deposits, @@ -893,8 +891,8 @@ void checkAvailableForResults( new BigDecimal(amt).divide(new BigDecimal(owings), 18, RoundingMode.HALF_DOWN); byte[] input = getAvailableForWithdrawalAtInput(contract, timestamp); - Set contributors = getAllDepositors(trs, contract); - for (AionAddress acc : contributors) { + Set
contributors = getAllDepositors(trs, contract); + for (Address acc : contributors) { PrecompiledTransactionResult res = newTRSqueryContract(acc).execute(input, COST); assertEquals(PrecompiledResultCode.SUCCESS, res.getResultCode()); BigDecimal frac = new BigDecimal(new BigInteger(res.getOutput())).movePointLeft(18); @@ -962,7 +960,7 @@ ByteArrayWrapper newDataWordStub(byte[] data) { */ private BigInteger expectedAmtFirstWithdraw( AbstractTRS trs, - AionAddress contract, + Address contract, BigInteger deposits, BigInteger total, BigInteger bonus, @@ -988,7 +986,7 @@ private BigInteger expectedAmtFirstWithdraw( } // Returns the contract specifications byte array associated with contract. - private byte[] getContractSpecs(AbstractTRS trs, AionAddress contract) { + private byte[] getContractSpecs(AbstractTRS trs, Address contract) { return trs.getContractSpecs(contract); } } diff --git a/modPrecompiled/test/org/aion/precompiled/TRS/TRSlinkedListTest.java b/modPrecompiled/test/org/aion/precompiled/TRS/TRSlinkedListTest.java index 1cb36b2dd0..5e1c78a2ff 100644 --- a/modPrecompiled/test/org/aion/precompiled/TRS/TRSlinkedListTest.java +++ b/modPrecompiled/test/org/aion/precompiled/TRS/TRSlinkedListTest.java @@ -16,6 +16,7 @@ import org.aion.precompiled.contracts.DummyRepo; import org.aion.precompiled.contracts.TRS.AbstractTRS; import org.aion.precompiled.contracts.TRS.TRSuseContract; +import org.aion.vm.api.interfaces.Address; import org.junit.After; import org.junit.Before; import org.junit.Test; @@ -33,7 +34,7 @@ public void setup() { @After public void tearDown() { - for (AionAddress acct : tempAddrs) { + for (Address acct : tempAddrs) { repo.deleteAccount(acct); } tempAddrs = null; @@ -43,8 +44,8 @@ public void tearDown() { @Test public void testLinkedListNoDepositors() { - AionAddress acct = getNewExistentAccount(DEFAULT_BALANCE); - AionAddress contract = createTRScontract(acct, false, true, 1, BigInteger.ZERO, 0); + Address acct = getNewExistentAccount(DEFAULT_BALANCE); + Address contract = createTRScontract(acct, false, true, 1, BigInteger.ZERO, 0); TRSuseContract trs = newTRSuseContract(acct); assertNull(getLinkedListHead(trs, contract)); } @@ -52,8 +53,8 @@ public void testLinkedListNoDepositors() { @Test public void testLinkedListOneDepositor() { // First test using deposit. - AionAddress acct = getNewExistentAccount(DEFAULT_BALANCE); - AionAddress contract = createTRScontract(acct, false, true, 1, BigInteger.ZERO, 0); + Address acct = getNewExistentAccount(DEFAULT_BALANCE); + Address contract = createTRScontract(acct, false, true, 1, BigInteger.ZERO, 0); byte[] input = getDepositInput(contract, BigInteger.ONE); TRSuseContract trs = newTRSuseContract(acct); assertEquals(PrecompiledResultCode.SUCCESS, trs.execute(input, COST).getResultCode()); @@ -72,9 +73,9 @@ public void testLinkedListOneDepositor() { @Test public void testLinkedListTwoDepositors() { // First test using deposit. - AionAddress acct = getNewExistentAccount(DEFAULT_BALANCE); - AionAddress acct2 = getNewExistentAccount(DEFAULT_BALANCE); - AionAddress contract = createTRScontract(acct, false, true, 1, BigInteger.ZERO, 0); + Address acct = getNewExistentAccount(DEFAULT_BALANCE); + Address acct2 = getNewExistentAccount(DEFAULT_BALANCE); + Address contract = createTRScontract(acct, false, true, 1, BigInteger.ZERO, 0); byte[] input = getDepositInput(contract, BigInteger.ONE); TRSuseContract trs = newTRSuseContract(acct); @@ -113,12 +114,12 @@ public void testLinkedListTwoDepositors() { @Test public void testLinkedListMultipleDepositors() { // First test using deposit. - AionAddress acct1, acct2, acct3, acct4; + Address acct1, acct2, acct3, acct4; acct1 = getNewExistentAccount(DEFAULT_BALANCE); acct2 = getNewExistentAccount(DEFAULT_BALANCE); acct3 = getNewExistentAccount(DEFAULT_BALANCE); acct4 = getNewExistentAccount(DEFAULT_BALANCE); - AionAddress contract = createTRScontract(acct1, false, true, 1, BigInteger.ZERO, 0); + Address contract = createTRScontract(acct1, false, true, 1, BigInteger.ZERO, 0); byte[] input = getDepositInput(contract, BigInteger.ONE); newTRSuseContract(acct1).execute(input, COST); @@ -159,8 +160,8 @@ public void testLinkedListMultipleDepositors() { @Test public void testRemoveHeadOfListWithHeadOnly() { // Test using deposit. - AionAddress acct = getNewExistentAccount(DEFAULT_BALANCE); - AionAddress contract = createTRScontract(acct, false, true, 1, BigInteger.ZERO, 0); + Address acct = getNewExistentAccount(DEFAULT_BALANCE); + Address contract = createTRScontract(acct, false, true, 1, BigInteger.ZERO, 0); byte[] input = getDepositInput(contract, DEFAULT_BALANCE); TRSuseContract trs = newTRSuseContract(acct); @@ -178,15 +179,16 @@ public void testRemoveHeadOfListWithHeadOnly() { @Test public void testRemoveHeadOfListWithHeadAndNextOnly() { // Test using deposit. - AionAddress acct = getNewExistentAccount(DEFAULT_BALANCE); - AionAddress acct2 = getNewExistentAccount(DEFAULT_BALANCE); - AionAddress contract = createTRScontract(acct, false, true, 1, BigInteger.ZERO, 0); + Address acct = getNewExistentAccount(DEFAULT_BALANCE); + Address acct2 = getNewExistentAccount(DEFAULT_BALANCE); + Address contract = createTRScontract(acct, false, true, 1, BigInteger.ZERO, 0); byte[] input = getDepositInput(contract, DEFAULT_BALANCE); TRSuseContract trs = newTRSuseContract(acct); assertEquals(PrecompiledResultCode.SUCCESS, trs.execute(input, COST).getResultCode()); assertEquals( - PrecompiledResultCode.SUCCESS, newTRSuseContract(acct2).execute(input, COST).getResultCode()); + PrecompiledResultCode.SUCCESS, + newTRSuseContract(acct2).execute(input, COST).getResultCode()); checkRemoveHeadOfListWithHeadAndNextOnly(trs, contract, acct, acct2); @@ -208,8 +210,8 @@ public void testRemoveHeadOfListWithHeadAndNextOnly() { public void testRemoveHeadOfLargerList() { // Test using deposit. int listSize = 10; - AionAddress owner = getNewExistentAccount(BigInteger.ONE); - AionAddress contract = + Address owner = getNewExistentAccount(BigInteger.ONE); + Address contract = getContractMultipleDepositors(listSize, owner, false, true, 1, BigInteger.ZERO, 0); checkRemoveHeadOfLargerList(contract, owner, listSize); @@ -226,15 +228,16 @@ public void testRemoveHeadOfLargerList() { @Test public void testRemoveTailOfSizeTwoList() { // Test using deposit. - AionAddress acct = getNewExistentAccount(DEFAULT_BALANCE); - AionAddress acct2 = getNewExistentAccount(DEFAULT_BALANCE); - AionAddress contract = createTRScontract(acct, false, true, 1, BigInteger.ZERO, 0); + Address acct = getNewExistentAccount(DEFAULT_BALANCE); + Address acct2 = getNewExistentAccount(DEFAULT_BALANCE); + Address contract = createTRScontract(acct, false, true, 1, BigInteger.ZERO, 0); byte[] input = getDepositInput(contract, DEFAULT_BALANCE); TRSuseContract trs = newTRSuseContract(acct); assertEquals(PrecompiledResultCode.SUCCESS, trs.execute(input, COST).getResultCode()); assertEquals( - PrecompiledResultCode.SUCCESS, newTRSuseContract(acct2).execute(input, COST).getResultCode()); + PrecompiledResultCode.SUCCESS, + newTRSuseContract(acct2).execute(input, COST).getResultCode()); checkRemoveTailOfSizeTwoList(trs, contract, acct, acct2); @@ -256,8 +259,8 @@ public void testRemoveTailOfSizeTwoList() { public void testRemoveTailOfLargerList() { // Test using deposit. int listSize = 10; - AionAddress owner = getNewExistentAccount(BigInteger.ONE); - AionAddress contract = + Address owner = getNewExistentAccount(BigInteger.ONE); + Address contract = getContractMultipleDepositors(listSize, owner, false, true, 1, BigInteger.ZERO, 0); checkRemoveTailOfLargerList(contract, owner, listSize); @@ -274,18 +277,20 @@ public void testRemoveTailOfLargerList() { @Test public void testRemoveInteriorOfSizeThreeList() { // Test using deposit. - AionAddress acct = getNewExistentAccount(DEFAULT_BALANCE); - AionAddress acct2 = getNewExistentAccount(DEFAULT_BALANCE); - AionAddress acct3 = getNewExistentAccount(DEFAULT_BALANCE); - AionAddress contract = createTRScontract(acct, false, true, 1, BigInteger.ZERO, 0); + Address acct = getNewExistentAccount(DEFAULT_BALANCE); + Address acct2 = getNewExistentAccount(DEFAULT_BALANCE); + Address acct3 = getNewExistentAccount(DEFAULT_BALANCE); + Address contract = createTRScontract(acct, false, true, 1, BigInteger.ZERO, 0); byte[] input = getDepositInput(contract, DEFAULT_BALANCE); TRSuseContract trs = newTRSuseContract(acct); assertEquals(PrecompiledResultCode.SUCCESS, trs.execute(input, COST).getResultCode()); assertEquals( - PrecompiledResultCode.SUCCESS, newTRSuseContract(acct2).execute(input, COST).getResultCode()); + PrecompiledResultCode.SUCCESS, + newTRSuseContract(acct2).execute(input, COST).getResultCode()); assertEquals( - PrecompiledResultCode.SUCCESS, newTRSuseContract(acct3).execute(input, COST).getResultCode()); + PrecompiledResultCode.SUCCESS, + newTRSuseContract(acct3).execute(input, COST).getResultCode()); checkRemoveInteriorOfSizeThreeList(trs, contract, acct, acct2, acct3); @@ -310,8 +315,8 @@ public void testRemoveInteriorOfSizeThreeList() { public void testRemoveInteriorOfLargerList() { // Test using deposit. int listSize = 10; - AionAddress owner = getNewExistentAccount(BigInteger.ONE); - AionAddress contract = + Address owner = getNewExistentAccount(BigInteger.ONE); + Address contract = getContractMultipleDepositors(listSize, owner, false, true, 1, BigInteger.ZERO, 0); checkRemoveInteriorOfLargerList(contract, owner, listSize); @@ -329,8 +334,8 @@ public void testRemoveInteriorOfLargerList() { public void testMultipleListRemovals() { // Test using deposit. int listSize = 10; - AionAddress owner = getNewExistentAccount(BigInteger.ONE); - AionAddress contract = + Address owner = getNewExistentAccount(BigInteger.ONE); + Address contract = getContractMultipleDepositors(listSize, owner, false, true, 1, BigInteger.ZERO, 0); checkMultipleListRemovals(contract, owner, listSize); @@ -347,7 +352,7 @@ public void testMultipleListRemovals() { // <---------------------------------------HELPERS BELOW---------------------------------------> private void checkLinkedListOneDepositor( - AbstractTRS trs, AionAddress contract, AionAddress acct, byte[] input) { + AbstractTRS trs, Address contract, Address acct, byte[] input) { assertEquals(acct, getLinkedListHead(trs, contract)); assertNull(getLinkedListNext(trs, contract, acct)); assertNull(getLinkedListPrev(trs, contract, acct)); @@ -362,7 +367,7 @@ private void checkLinkedListOneDepositor( // We expect a list with acct2 as head as such: null <- acct2 <-> acct -> null private void checkLinkedListTwoDepositors( - AbstractTRS trs, AionAddress contract, AionAddress acct, AionAddress acct2) { + AbstractTRS trs, Address contract, Address acct, Address acct2) { assertEquals(acct2, getLinkedListHead(trs, contract)); assertEquals(acct, getLinkedListNext(trs, contract, acct2)); @@ -373,7 +378,7 @@ private void checkLinkedListTwoDepositors( // Expect a list with acct3 as head as such: null <- acct3 <-> acct2 <-> acct4 <-> acct1 -> null private void checkLinkedListMultipleDepositors( - AionAddress contract, AionAddress acct1, AionAddress acct2, AionAddress acct3, AionAddress acct4) { + Address contract, Address acct1, Address acct2, Address acct3, Address acct4) { TRSuseContract trs = newTRSuseContract(acct1); assertEquals(acct3, getLinkedListHead(trs, contract)); @@ -388,7 +393,7 @@ private void checkLinkedListMultipleDepositors( } private void checkRemoveHeadOfListWithHeadOnly( - AbstractTRS trs, AionAddress contract, AionAddress acct, byte[] input) { + AbstractTRS trs, Address contract, Address acct, byte[] input) { assertEquals(PrecompiledResultCode.SUCCESS, trs.execute(input, COST).getResultCode()); @@ -405,7 +410,7 @@ private void checkRemoveHeadOfListWithHeadOnly( // Expects acct2 as head with: null <- acct2 <-> acct -> null private void checkRemoveHeadOfListWithHeadAndNextOnly( - AbstractTRS trs, AionAddress contract, AionAddress acct, AionAddress acct2) { + AbstractTRS trs, Address contract, Address acct, Address acct2) { assertEquals(acct2, getLinkedListHead(trs, contract)); assertEquals(acct, getLinkedListNext(trs, contract, acct2)); @@ -423,11 +428,11 @@ private void checkRemoveHeadOfListWithHeadAndNextOnly( assertNull(getLinkedListPrev(trs, contract, acct)); } - private void checkRemoveHeadOfLargerList(AionAddress contract, AionAddress owner, int listSize) { + private void checkRemoveHeadOfLargerList(Address contract, Address owner, int listSize) { // We have a linked list with 10 depositors. Remove the head. TRSuseContract trs = newTRSuseContract(owner); - AionAddress head = getLinkedListHead(trs, contract); - AionAddress next = getLinkedListNext(trs, contract, head); + Address head = getLinkedListHead(trs, contract); + Address next = getLinkedListNext(trs, contract, head); assertNull(getLinkedListPrev(trs, contract, head)); assertEquals(head, getLinkedListPrev(trs, contract, next)); byte[] input = getRefundInput(contract, head, DEFAULT_BALANCE); @@ -439,7 +444,7 @@ private void checkRemoveHeadOfLargerList(AionAddress contract, AionAddress owner assertNull(getLinkedListPrev(trs, contract, next)); // We also make sure each address in the list is unique. - Set addressesInList = new HashSet<>(); + Set
addressesInList = new HashSet<>(); for (int i = 0; i < listSize - 1; i++) { if (i == listSize - 2) { assertNull(getLinkedListNext(trs, contract, next)); @@ -454,7 +459,7 @@ private void checkRemoveHeadOfLargerList(AionAddress contract, AionAddress owner // Expects acct2 as head with: null <- acct2 <-> acct -> null private void checkRemoveTailOfSizeTwoList( - AbstractTRS trs, AionAddress contract, AionAddress acct, AionAddress acct2) { + AbstractTRS trs, Address contract, Address acct, Address acct2) { assertEquals(acct2, getLinkedListHead(trs, contract)); assertEquals(acct, getLinkedListNext(trs, contract, acct2)); @@ -472,13 +477,13 @@ private void checkRemoveTailOfSizeTwoList( assertNull(getLinkedListPrev(trs, contract, acct2)); } - private void checkRemoveTailOfLargerList(AionAddress contract, AionAddress owner, int listSize) { + private void checkRemoveTailOfLargerList(Address contract, Address owner, int listSize) { // We have a linked list with 10 depositors. First find the tail. Ensure each address is // unique too. TRSuseContract trs = newTRSuseContract(owner); - AionAddress next = getLinkedListHead(trs, contract); - AionAddress head = new AionAddress(next.toBytes()); - Set addressesInList = new HashSet<>(); + Address next = getLinkedListHead(trs, contract); + Address head = new AionAddress(next.toBytes()); + Set
addressesInList = new HashSet<>(); for (int i = 0; i < listSize; i++) { if (i == listSize - 1) { assertNull(getLinkedListNext(trs, contract, next)); @@ -510,7 +515,7 @@ private void checkRemoveTailOfLargerList(AionAddress contract, AionAddress owner // Expects acct3 as head with: null <- acct3 <-> acct2 <-> acct -> null private void checkRemoveInteriorOfSizeThreeList( - AbstractTRS trs, AionAddress contract, AionAddress acct, AionAddress acct2, AionAddress acct3) { + AbstractTRS trs, Address contract, Address acct, Address acct2, Address acct3) { assertEquals(acct3, getLinkedListHead(trs, contract)); assertEquals(acct2, getLinkedListNext(trs, contract, acct3)); @@ -532,14 +537,14 @@ private void checkRemoveInteriorOfSizeThreeList( assertNull(getLinkedListPrev(trs, contract, acct3)); } - private void checkRemoveInteriorOfLargerList(AionAddress contract, AionAddress owner, int listSize) { + private void checkRemoveInteriorOfLargerList(Address contract, Address owner, int listSize) { // We have a linked list with 10 depositors. Grab the 5th in line. Ensure each address is // unique too. TRSuseContract trs = newTRSuseContract(owner); - AionAddress next = getLinkedListHead(trs, contract); - AionAddress head = new AionAddress(next.toBytes()); - AionAddress mid = null; - Set addressesInList = new HashSet<>(); + Address next = getLinkedListHead(trs, contract); + Address head = new AionAddress(next.toBytes()); + Address mid = null; + Set
addressesInList = new HashSet<>(); for (int i = 0; i < listSize; i++) { if (i == listSize - 1) { assertNull(getLinkedListNext(trs, contract, next)); @@ -575,13 +580,13 @@ private void checkRemoveInteriorOfLargerList(AionAddress contract, AionAddress o } } - private void checkMultipleListRemovals(AionAddress contract, AionAddress owner, int listSize) { + private void checkMultipleListRemovals(Address contract, Address owner, int listSize) { // We have a linked list with 10 depositors. Ensure each address is unique. Grab every other // address to remove. TRSuseContract trs = newTRSuseContract(owner); - AionAddress next = getLinkedListHead(trs, contract); - Set removals = new HashSet<>(); - Set addressesInList = new HashSet<>(); + Address next = getLinkedListHead(trs, contract); + Set
removals = new HashSet<>(); + Set
addressesInList = new HashSet<>(); for (int i = 0; i < listSize; i++) { if (i == listSize - 1) { assertNull(getLinkedListNext(trs, contract, next)); @@ -597,14 +602,14 @@ private void checkMultipleListRemovals(AionAddress contract, AionAddress owner, } // Remove all accts in removals. Iterate over list again. - for (AionAddress rm : removals) { + for (Address rm : removals) { byte[] input = getRefundInput(contract, rm, DEFAULT_BALANCE); assertEquals(PrecompiledResultCode.SUCCESS, trs.execute(input, COST).getResultCode()); assertFalse(accountIsValid(trs, contract, rm)); } // Note: may give +/-1 errors if listSize is not divisible by 2. - AionAddress head = getLinkedListHead(trs, contract); + Address head = getLinkedListHead(trs, contract); assertFalse(removals.contains(head)); for (int i = 0; i < listSize / 2; i++) { if (i == (listSize / 2) - 1) { diff --git a/modPrecompiled/test/org/aion/precompiled/TRS/TRSqueryContractTest.java b/modPrecompiled/test/org/aion/precompiled/TRS/TRSqueryContractTest.java index fb828d55a3..cca130e5b6 100644 --- a/modPrecompiled/test/org/aion/precompiled/TRS/TRSqueryContractTest.java +++ b/modPrecompiled/test/org/aion/precompiled/TRS/TRSqueryContractTest.java @@ -19,6 +19,7 @@ import org.aion.precompiled.contracts.TRS.AbstractTRS; import org.aion.precompiled.contracts.TRS.TRSqueryContract; import org.aion.precompiled.type.StatefulPrecompiledContract; +import org.aion.vm.api.interfaces.Address; import org.junit.After; import org.junit.Before; import org.junit.Test; @@ -37,7 +38,7 @@ public void setup() { @After public void tearDown() { - for (AionAddress acct : tempAddrs) { + for (Address acct : tempAddrs) { repo.deleteAccount(acct); } tempAddrs = null; @@ -70,7 +71,7 @@ public void testCreateEmptyInput() { @Test public void testInsufficientNrg() { - AionAddress addr = getNewExistentAccount(BigInteger.ZERO); + Address addr = getNewExistentAccount(BigInteger.ZERO); TRSqueryContract trs = newTRSqueryContract(addr); byte[] input = getDepositInput(addr, BigInteger.ZERO); PrecompiledTransactionResult res; @@ -83,7 +84,7 @@ public void testInsufficientNrg() { @Test public void testTooMuchNrg() { - AionAddress addr = getNewExistentAccount(BigInteger.ZERO); + Address addr = getNewExistentAccount(BigInteger.ZERO); TRSqueryContract trs = newTRSqueryContract(addr); byte[] input = getDepositInput(addr, BigInteger.ZERO); PrecompiledTransactionResult res; @@ -96,13 +97,14 @@ public void testTooMuchNrg() { @Test public void testInvalidOperation() { - AionAddress addr = getNewExistentAccount(BigInteger.ONE); + Address addr = getNewExistentAccount(BigInteger.ONE); TRSqueryContract trs = newTRSqueryContract(addr); byte[] input = new byte[DoubleDataWord.BYTES]; for (int i = Byte.MIN_VALUE; i <= Byte.MAX_VALUE; i++) { if ((i < 0) || (i > MAX_OP)) { input[0] = (byte) i; - assertEquals(PrecompiledResultCode.FAILURE, trs.execute(input, COST).getResultCode()); + assertEquals( + PrecompiledResultCode.FAILURE, trs.execute(input, COST).getResultCode()); } } } @@ -111,7 +113,7 @@ public void testInvalidOperation() { @Test public void testIsLiveInputTooShort() { - AionAddress acct = getNewExistentAccount(DEFAULT_BALANCE); + Address acct = getNewExistentAccount(DEFAULT_BALANCE); byte[] input = new byte[32]; PrecompiledTransactionResult res = newTRSqueryContract(acct).execute(input, COST); assertEquals(PrecompiledResultCode.FAILURE, res.getResultCode()); @@ -120,7 +122,7 @@ public void testIsLiveInputTooShort() { @Test public void testIsLiveInputTooLong() { - AionAddress acct = getNewExistentAccount(DEFAULT_BALANCE); + Address acct = getNewExistentAccount(DEFAULT_BALANCE); byte[] input = new byte[34]; PrecompiledTransactionResult res = newTRSqueryContract(acct).execute(input, COST); assertEquals(PrecompiledResultCode.FAILURE, res.getResultCode()); @@ -130,7 +132,7 @@ public void testIsLiveInputTooLong() { @Test public void testIsLiveNonExistentContract() { // Test on a contract address that is just a regular account address. - AionAddress acct = getNewExistentAccount(DEFAULT_BALANCE); + Address acct = getNewExistentAccount(DEFAULT_BALANCE); byte[] input = getIsLiveInput(acct); PrecompiledTransactionResult res = newTRSqueryContract(acct).execute(input, COST); assertEquals(PrecompiledResultCode.SUCCESS, res.getResultCode()); @@ -149,8 +151,8 @@ public void testIsLiveNonExistentContract() { @Test public void testIsLiveOnUnlockedContract() { - AionAddress acct = getNewExistentAccount(DEFAULT_BALANCE); - AionAddress contract = createTRScontract(acct, false, true, 1, BigInteger.ZERO, 0); + Address acct = getNewExistentAccount(DEFAULT_BALANCE); + Address contract = createTRScontract(acct, false, true, 1, BigInteger.ZERO, 0); byte[] input = getIsLiveInput(contract); PrecompiledTransactionResult res = newTRSqueryContract(acct).execute(input, COST); assertEquals(PrecompiledResultCode.SUCCESS, res.getResultCode()); @@ -160,8 +162,8 @@ public void testIsLiveOnUnlockedContract() { @Test public void testIsLiveOnLockedContract() { - AionAddress acct = getNewExistentAccount(DEFAULT_BALANCE); - AionAddress contract = createAndLockTRScontract(acct, false, true, 1, BigInteger.ZERO, 0); + Address acct = getNewExistentAccount(DEFAULT_BALANCE); + Address contract = createAndLockTRScontract(acct, false, true, 1, BigInteger.ZERO, 0); byte[] input = getIsLiveInput(contract); PrecompiledTransactionResult res = newTRSqueryContract(acct).execute(input, COST); assertEquals(PrecompiledResultCode.SUCCESS, res.getResultCode()); @@ -171,8 +173,8 @@ public void testIsLiveOnLockedContract() { @Test public void testIsLiveOnLiveContract() { - AionAddress acct = getNewExistentAccount(DEFAULT_BALANCE); - AionAddress contract = createLockedAndLiveTRScontract(acct, false, true, 1, BigInteger.ZERO, 0); + Address acct = getNewExistentAccount(DEFAULT_BALANCE); + Address contract = createLockedAndLiveTRScontract(acct, false, true, 1, BigInteger.ZERO, 0); byte[] input = getIsLiveInput(contract); PrecompiledTransactionResult res = newTRSqueryContract(acct).execute(input, COST); assertEquals(PrecompiledResultCode.SUCCESS, res.getResultCode()); @@ -184,7 +186,7 @@ public void testIsLiveOnLiveContract() { @Test public void testIsLockedInputTooShort() { - AionAddress acct = getNewExistentAccount(DEFAULT_BALANCE); + Address acct = getNewExistentAccount(DEFAULT_BALANCE); byte[] input = new byte[32]; input[0] = 0x1; PrecompiledTransactionResult res = newTRSqueryContract(acct).execute(input, COST); @@ -194,7 +196,7 @@ public void testIsLockedInputTooShort() { @Test public void testIsLockedInputTooLong() { - AionAddress acct = getNewExistentAccount(DEFAULT_BALANCE); + Address acct = getNewExistentAccount(DEFAULT_BALANCE); byte[] input = new byte[34]; input[0] = 0x1; PrecompiledTransactionResult res = newTRSqueryContract(acct).execute(input, COST); @@ -205,7 +207,7 @@ public void testIsLockedInputTooLong() { @Test public void testIsLockedNonExistentContract() { // Test on a contract address that is just a regular account address. - AionAddress acct = getNewExistentAccount(DEFAULT_BALANCE); + Address acct = getNewExistentAccount(DEFAULT_BALANCE); byte[] input = getIsLockedInput(acct); PrecompiledTransactionResult res = newTRSqueryContract(acct).execute(input, COST); assertEquals(PrecompiledResultCode.SUCCESS, res.getResultCode()); @@ -224,8 +226,8 @@ public void testIsLockedNonExistentContract() { @Test public void testIsLockedOnUnlockedContract() { - AionAddress acct = getNewExistentAccount(DEFAULT_BALANCE); - AionAddress contract = createTRScontract(acct, false, true, 1, BigInteger.ZERO, 0); + Address acct = getNewExistentAccount(DEFAULT_BALANCE); + Address contract = createTRScontract(acct, false, true, 1, BigInteger.ZERO, 0); byte[] input = getIsLockedInput(contract); PrecompiledTransactionResult res = newTRSqueryContract(acct).execute(input, COST); assertEquals(PrecompiledResultCode.SUCCESS, res.getResultCode()); @@ -235,8 +237,8 @@ public void testIsLockedOnUnlockedContract() { @Test public void testIsLockedOnLockedContract() { - AionAddress acct = getNewExistentAccount(DEFAULT_BALANCE); - AionAddress contract = createAndLockTRScontract(acct, false, true, 1, BigInteger.ZERO, 0); + Address acct = getNewExistentAccount(DEFAULT_BALANCE); + Address contract = createAndLockTRScontract(acct, false, true, 1, BigInteger.ZERO, 0); byte[] input = getIsLockedInput(contract); PrecompiledTransactionResult res = newTRSqueryContract(acct).execute(input, COST); assertEquals(PrecompiledResultCode.SUCCESS, res.getResultCode()); @@ -246,8 +248,8 @@ public void testIsLockedOnLockedContract() { @Test public void testIsLockedOnLiveContract() { - AionAddress acct = getNewExistentAccount(DEFAULT_BALANCE); - AionAddress contract = createLockedAndLiveTRScontract(acct, false, true, 1, BigInteger.ZERO, 0); + Address acct = getNewExistentAccount(DEFAULT_BALANCE); + Address contract = createLockedAndLiveTRScontract(acct, false, true, 1, BigInteger.ZERO, 0); byte[] input = getIsLockedInput(contract); PrecompiledTransactionResult res = newTRSqueryContract(acct).execute(input, COST); assertEquals(PrecompiledResultCode.SUCCESS, res.getResultCode()); @@ -259,7 +261,7 @@ public void testIsLockedOnLiveContract() { @Test public void testIsDepoEnabledInputTooShort() { - AionAddress acct = getNewExistentAccount(DEFAULT_BALANCE); + Address acct = getNewExistentAccount(DEFAULT_BALANCE); byte[] input = new byte[32]; input[0] = 0x2; PrecompiledTransactionResult res = newTRSqueryContract(acct).execute(input, COST); @@ -269,7 +271,7 @@ public void testIsDepoEnabledInputTooShort() { @Test public void testIsDepoEnabledInputTooLong() { - AionAddress acct = getNewExistentAccount(DEFAULT_BALANCE); + Address acct = getNewExistentAccount(DEFAULT_BALANCE); byte[] input = new byte[34]; input[0] = 0x2; PrecompiledTransactionResult res = newTRSqueryContract(acct).execute(input, COST); @@ -280,7 +282,7 @@ public void testIsDepoEnabledInputTooLong() { @Test public void testIsDepoEnabledNonExistentContract() { // Test on a contract address that is just a regular account address. - AionAddress acct = getNewExistentAccount(DEFAULT_BALANCE); + Address acct = getNewExistentAccount(DEFAULT_BALANCE); byte[] input = getIsDirDepoEnabledInput(acct); PrecompiledTransactionResult res = newTRSqueryContract(acct).execute(input, COST); assertEquals(PrecompiledResultCode.SUCCESS, res.getResultCode()); @@ -299,8 +301,8 @@ public void testIsDepoEnabledNonExistentContract() { @Test public void testIsDepoEnabledWhenDisabled() { - AionAddress acct = getNewExistentAccount(DEFAULT_BALANCE); - AionAddress contract = createTRScontract(acct, false, false, 1, BigInteger.ZERO, 0); + Address acct = getNewExistentAccount(DEFAULT_BALANCE); + Address contract = createTRScontract(acct, false, false, 1, BigInteger.ZERO, 0); byte[] input = getIsDirDepoEnabledInput(contract); PrecompiledTransactionResult res = newTRSqueryContract(acct).execute(input, COST); assertEquals(PrecompiledResultCode.SUCCESS, res.getResultCode()); @@ -310,8 +312,8 @@ public void testIsDepoEnabledWhenDisabled() { @Test public void testIsDepoEnabledWhenEnabled() { - AionAddress acct = getNewExistentAccount(DEFAULT_BALANCE); - AionAddress contract = createTRScontract(acct, false, true, 1, BigInteger.ZERO, 0); + Address acct = getNewExistentAccount(DEFAULT_BALANCE); + Address contract = createTRScontract(acct, false, true, 1, BigInteger.ZERO, 0); byte[] input = getIsDirDepoEnabledInput(contract); PrecompiledTransactionResult res = newTRSqueryContract(acct).execute(input, COST); assertEquals(PrecompiledResultCode.SUCCESS, res.getResultCode()); @@ -323,7 +325,7 @@ public void testIsDepoEnabledWhenEnabled() { @Test public void testPeriodInputTooShort() { - AionAddress acct = getNewExistentAccount(DEFAULT_BALANCE); + Address acct = getNewExistentAccount(DEFAULT_BALANCE); byte[] input = new byte[32]; input[0] = 0x3; PrecompiledTransactionResult res = newTRSqueryContract(acct).execute(input, COST); @@ -333,7 +335,7 @@ public void testPeriodInputTooShort() { @Test public void testPeriodInputTooLong() { - AionAddress acct = getNewExistentAccount(DEFAULT_BALANCE); + Address acct = getNewExistentAccount(DEFAULT_BALANCE); byte[] input = new byte[34]; input[0] = 0x3; PrecompiledTransactionResult res = newTRSqueryContract(acct).execute(input, COST); @@ -343,7 +345,7 @@ public void testPeriodInputTooLong() { @Test public void testPeriodOfNonExistentContract() { - AionAddress acct = getNewExistentAccount(DEFAULT_BALANCE); + Address acct = getNewExistentAccount(DEFAULT_BALANCE); byte[] input = getPeriodInput(acct); PrecompiledTransactionResult res = newTRSqueryContract(acct).execute(input, COST); assertEquals(PrecompiledResultCode.FAILURE, res.getResultCode()); @@ -352,7 +354,7 @@ public void testPeriodOfNonExistentContract() { @Test public void testPeriodBeforeIsLive() { - AionAddress contract = createAndLockTRScontract(AION, true, true, 4, BigInteger.ZERO, 0); + Address contract = createAndLockTRScontract(AION, true, true, 4, BigInteger.ZERO, 0); AbstractTRS trs = newTRSqueryContract(AION); mockBlockchain(getContractTimestamp(trs, contract) + 2); @@ -364,7 +366,7 @@ public void testPeriodBeforeIsLive() { @Test public void testPeriodOnEmptyBlockchain() { - AionAddress contract = createLockedAndLiveTRScontract(AION, true, true, 4, BigInteger.ZERO, 0); + Address contract = createLockedAndLiveTRScontract(AION, true, true, 4, BigInteger.ZERO, 0); mockBlockchain(0); // We are using a timestamp of zero and therefore we are in period 0 at this point. @@ -377,7 +379,7 @@ public void testPeriodOnEmptyBlockchain() { @Test public void testPeriodContractDeployedAfterBestBlock() { mockBlockchain(0); - AionAddress contract = createLockedAndLiveTRScontract(AION, true, true, 5, BigInteger.ZERO, 0); + Address contract = createLockedAndLiveTRScontract(AION, true, true, 5, BigInteger.ZERO, 0); // In period zero. byte[] input = getPeriodInput(contract); @@ -389,7 +391,7 @@ public void testPeriodContractDeployedAfterBestBlock() { @Test public void testPeriodWhenPeriodsIsOne() { mockBlockchain(0); - AionAddress contract = createLockedAndLiveTRScontract(AION, true, true, 1, BigInteger.ZERO, 0); + Address contract = createLockedAndLiveTRScontract(AION, true, true, 1, BigInteger.ZERO, 0); // Period is zero. byte[] input = getPeriodInput(contract); @@ -418,7 +420,7 @@ public void testPeriodWhenPeriodsIsOne() { @Test public void testPeriodAtDifferentMoments() { int numPeriods = 4; - AionAddress contract = + Address contract = createLockedAndLiveTRScontract(AION, true, true, numPeriods, BigInteger.ZERO, 0); AbstractTRS trs = newTRSqueryContract(AION); mockBlockchain(getContractTimestamp(trs, contract)); @@ -450,7 +452,7 @@ public void testPeriodAtDifferentMoments() { @Test public void testPeriodAtInputTooShort() { - AionAddress acct = getNewExistentAccount(DEFAULT_BALANCE); + Address acct = getNewExistentAccount(DEFAULT_BALANCE); byte[] input = new byte[32]; input[0] = 0x4; PrecompiledTransactionResult res = newTRSqueryContract(acct).execute(input, COST); @@ -460,7 +462,7 @@ public void testPeriodAtInputTooShort() { @Test public void testPeriodAtInputTooLong() { - AionAddress acct = getNewExistentAccount(DEFAULT_BALANCE); + Address acct = getNewExistentAccount(DEFAULT_BALANCE); byte[] input = new byte[34]; input[0] = 0x4; PrecompiledTransactionResult res = newTRSqueryContract(acct).execute(input, COST); @@ -470,7 +472,7 @@ public void testPeriodAtInputTooLong() { @Test public void testPeriodAtNonExistentContract() { - AionAddress acct = getNewExistentAccount(DEFAULT_BALANCE); + Address acct = getNewExistentAccount(DEFAULT_BALANCE); byte[] input = getPeriodAtInput(acct, 0); PrecompiledTransactionResult res = newTRSqueryContract(acct).execute(input, COST); assertEquals(PrecompiledResultCode.FAILURE, res.getResultCode()); @@ -479,8 +481,8 @@ public void testPeriodAtNonExistentContract() { @Test public void testPeriodAtNegativeBlockNumber() { - AionAddress acct = getNewExistentAccount(DEFAULT_BALANCE); - AionAddress contract = createLockedAndLiveTRScontract(acct, false, true, 1, BigInteger.ZERO, 0); + Address acct = getNewExistentAccount(DEFAULT_BALANCE); + Address contract = createLockedAndLiveTRScontract(acct, false, true, 1, BigInteger.ZERO, 0); byte[] input = getPeriodAtInput(contract, -1); PrecompiledTransactionResult res = newTRSqueryContract(acct).execute(input, COST); assertEquals(PrecompiledResultCode.FAILURE, res.getResultCode()); @@ -491,8 +493,8 @@ public void testPeriodAtNegativeBlockNumber() { public void testPeriodAtBlockTooLargeAndDoesNotExist() { int numBlocks = 1; - AionAddress acct = getNewExistentAccount(DEFAULT_BALANCE); - AionAddress contract = createLockedAndLiveTRScontract(acct, false, true, 1, BigInteger.ZERO, 0); + Address acct = getNewExistentAccount(DEFAULT_BALANCE); + Address contract = createLockedAndLiveTRScontract(acct, false, true, 1, BigInteger.ZERO, 0); mockBlockchain(0); byte[] input = getPeriodAtInput(contract, numBlocks + 1); @@ -505,7 +507,7 @@ public void testPeriodAtBlockTooLargeAndDoesNotExist() { public void testPeriodAtBeforeIsLive() { int numBlocks = 5; - AionAddress contract = createAndLockTRScontract(AION, true, true, 4, BigInteger.ZERO, 0); + Address contract = createAndLockTRScontract(AION, true, true, 4, BigInteger.ZERO, 0); AbstractTRS trs = newTRSqueryContract(AION); mockBlockchain(getContractTimestamp(trs, contract) + 5); @@ -517,7 +519,7 @@ public void testPeriodAtBeforeIsLive() { @Test public void testPeriodAtAfterIsLive() { - AionAddress contract = createLockedAndLiveTRScontract(AION, true, true, 4, BigInteger.ZERO, 0); + Address contract = createLockedAndLiveTRScontract(AION, true, true, 4, BigInteger.ZERO, 0); AbstractTRS trs = newTRSqueryContract(AION); long blockNum = 1; long timestamp = getContractTimestamp(trs, contract) + 1; @@ -547,7 +549,7 @@ public void testPeriodAtMaxPeriods() { int periods = 5; int numBlocks = 10; - AionAddress contract = + Address contract = createLockedAndLiveTRScontract(AION, true, true, periods, BigInteger.ZERO, 0); AbstractTRS trs = newTRSqueryContract(AION); long blockNum = periods; @@ -577,7 +579,7 @@ public void testPeriodAtMaxPeriods() { public void testPeriodAtWhenPeriodsIsOne() { int numBlocks = 5; - AionAddress contract = createLockedAndLiveTRScontract(AION, true, true, 1, BigInteger.ZERO, 0); + Address contract = createLockedAndLiveTRScontract(AION, true, true, 1, BigInteger.ZERO, 0); AbstractTRS trs = newTRSqueryContract(AION); long blockNum = 1; long timestamp = getContractTimestamp(trs, contract) + 1; @@ -604,8 +606,8 @@ public void testPeriodAtWhenPeriodsIsOne() { @Test public void testAvailableForInputTooShort() { - AionAddress acct = getNewExistentAccount(DEFAULT_BALANCE); - AionAddress contract = createTRScontract(acct, false, true, 7, BigInteger.ZERO, 0); + Address acct = getNewExistentAccount(DEFAULT_BALANCE); + Address contract = createTRScontract(acct, false, true, 7, BigInteger.ZERO, 0); byte[] input = getAvailableForWithdrawalAtInput(contract, 0); byte[] shortInput = Arrays.copyOf(input, input.length - 1); assertEquals( @@ -615,8 +617,8 @@ public void testAvailableForInputTooShort() { @Test public void testAvailableForInputTooLong() { - AionAddress acct = getNewExistentAccount(DEFAULT_BALANCE); - AionAddress contract = createTRScontract(acct, false, true, 7, BigInteger.ZERO, 0); + Address acct = getNewExistentAccount(DEFAULT_BALANCE); + Address contract = createTRScontract(acct, false, true, 7, BigInteger.ZERO, 0); byte[] input = getAvailableForWithdrawalAtInput(contract, 0); byte[] longInput = new byte[input.length + 1]; System.arraycopy(input, 0, longInput, 0, input.length); @@ -627,7 +629,7 @@ public void testAvailableForInputTooLong() { @Test public void testAvailableForContractNonExistent() { - AionAddress acct = getNewExistentAccount(DEFAULT_BALANCE); + Address acct = getNewExistentAccount(DEFAULT_BALANCE); byte[] input = getAvailableForWithdrawalAtInput(acct, 0); assertEquals( PrecompiledResultCode.FAILURE, @@ -636,8 +638,8 @@ public void testAvailableForContractNonExistent() { @Test public void testAvailableForContractNotYetLive() { - AionAddress acct = getNewExistentAccount(DEFAULT_BALANCE); - AionAddress contract = createTRScontract(acct, false, true, 7, BigInteger.ZERO, 0); + Address acct = getNewExistentAccount(DEFAULT_BALANCE); + Address contract = createTRScontract(acct, false, true, 7, BigInteger.ZERO, 0); byte[] input = getAvailableForWithdrawalAtInput(contract, 0); assertEquals( PrecompiledResultCode.FAILURE, @@ -651,7 +653,7 @@ public void testAvailableForNoSpecial() { BigInteger deposits = new BigInteger("3285423852334"); BigInteger bonus = new BigInteger("32642352"); BigDecimal percent = BigDecimal.ZERO; - AionAddress contract = setupContract(numDepositors, deposits, bonus, periods, percent); + Address contract = setupContract(numDepositors, deposits, bonus, periods, percent); AbstractTRS trs = newTRSstateContract(AION); long timestamp = trs.getTimestamp(contract) + (periods / 5); @@ -670,7 +672,7 @@ public void testAvailableForWithSpecial() { BigInteger deposits = new BigInteger("3245323"); BigInteger bonus = new BigInteger("34645"); BigDecimal percent = new BigDecimal("31.484645467"); - AionAddress contract = setupContract(numDepositors, deposits, bonus, periods, percent); + Address contract = setupContract(numDepositors, deposits, bonus, periods, percent); AbstractTRS trs = newTRSstateContract(AION); long timestamp = trs.getTimestamp(contract) + (periods / 3); @@ -689,7 +691,7 @@ public void testAvailableForInFinalPeriod() { BigInteger deposits = new BigInteger("237523675328"); BigInteger bonus = new BigInteger("2356236434"); BigDecimal percent = new BigDecimal("19.213343253242"); - AionAddress contract = setupContract(numDepositors, deposits, bonus, periods, percent); + Address contract = setupContract(numDepositors, deposits, bonus, periods, percent); AbstractTRS trs = newTRSstateContract(AION); long timestamp = trs.getTimestamp(contract) + periods; @@ -698,8 +700,8 @@ public void testAvailableForInFinalPeriod() { expectedFraction = expectedFraction.setScale(18, RoundingMode.HALF_DOWN); byte[] input = getAvailableForWithdrawalAtInput(contract, timestamp); - Set contributors = getAllDepositors(trs, contract); - for (AionAddress acc : contributors) { + Set
contributors = getAllDepositors(trs, contract); + for (Address acc : contributors) { PrecompiledTransactionResult res = newTRSqueryContract(acc).execute(input, COST); assertEquals(PrecompiledResultCode.SUCCESS, res.getResultCode()); BigDecimal frac = new BigDecimal(new BigInteger(res.getOutput())).movePointLeft(18); @@ -714,7 +716,7 @@ public void testAvailableForAtStartTime() { BigInteger deposits = new BigInteger("2357862387523"); BigInteger bonus = new BigInteger("35625365"); BigDecimal percent = new BigDecimal("10.2353425"); - AionAddress contract = setupContract(numDepositors, deposits, bonus, periods, percent); + Address contract = setupContract(numDepositors, deposits, bonus, periods, percent); AbstractTRS trs = newTRSstateContract(AION); long timestamp = trs.getTimestamp(contract); @@ -729,7 +731,7 @@ public void testAvailableForTimePriorToStartTime() { BigInteger deposits = new BigInteger("43634346"); BigInteger bonus = new BigInteger("23532"); BigDecimal percent = new BigDecimal("11"); - AionAddress contract = setupContract(numDepositors, deposits, bonus, periods, percent); + Address contract = setupContract(numDepositors, deposits, bonus, periods, percent); AbstractTRS trs = newTRSstateContract(AION); long timestamp = trs.getTimestamp(contract) - 1; @@ -738,8 +740,8 @@ public void testAvailableForTimePriorToStartTime() { expectedFraction = expectedFraction.setScale(18, RoundingMode.HALF_DOWN); byte[] input = getAvailableForWithdrawalAtInput(contract, timestamp); - Set contributors = getAllDepositors(trs, contract); - for (AionAddress acc : contributors) { + Set
contributors = getAllDepositors(trs, contract); + for (Address acc : contributors) { PrecompiledTransactionResult res = newTRSqueryContract(acc).execute(input, COST); assertEquals(PrecompiledResultCode.SUCCESS, res.getResultCode()); BigDecimal frac = new BigDecimal(new BigInteger(res.getOutput())).movePointLeft(18); @@ -754,7 +756,7 @@ public void testAvailableForMaxPeriods() { BigInteger deposits = new BigInteger("23869234762532654734875"); BigInteger bonus = new BigInteger("23434634634"); BigDecimal percent = new BigDecimal("6.1"); - AionAddress contract = setupContract(numDepositors, deposits, bonus, periods, percent); + Address contract = setupContract(numDepositors, deposits, bonus, periods, percent); AbstractTRS trs = newTRSstateContract(AION); long timestamp = trs.getTimestamp(contract) + (periods / 7); diff --git a/modPrecompiled/test/org/aion/precompiled/TRS/TRSstateContractTest.java b/modPrecompiled/test/org/aion/precompiled/TRS/TRSstateContractTest.java index 963793a943..56edd61735 100644 --- a/modPrecompiled/test/org/aion/precompiled/TRS/TRSstateContractTest.java +++ b/modPrecompiled/test/org/aion/precompiled/TRS/TRSstateContractTest.java @@ -21,6 +21,7 @@ import org.aion.precompiled.contracts.TRS.AbstractTRS; import org.aion.precompiled.contracts.TRS.TRSstateContract; import org.aion.precompiled.type.StatefulPrecompiledContract; +import org.aion.vm.api.interfaces.Address; import org.junit.After; import org.junit.Before; import org.junit.Test; @@ -40,7 +41,7 @@ public void setup() { @After public void tearDown() { - for (AionAddress acct : tempAddrs) { + for (Address acct : tempAddrs) { repo.deleteAccount(acct); } tempAddrs = null; @@ -83,20 +84,22 @@ public void testCreateInsufficientNrg() { public void testCreateTooMuchNrg() { byte[] input = getCreateInput(false, false, 1, BigInteger.ZERO, 0); TRSstateContract trs = newTRSstateContract(getNewExistentAccount(BigInteger.ZERO)); - PrecompiledTransactionResult res = trs.execute(input, StatefulPrecompiledContract.TX_NRG_MAX + 1); + PrecompiledTransactionResult res = + trs.execute(input, StatefulPrecompiledContract.TX_NRG_MAX + 1); assertEquals(PrecompiledResultCode.INVALID_NRG_LIMIT, res.getResultCode()); assertEquals(0, res.getEnergyRemaining()); } @Test public void testInvalidOperation() { - AionAddress addr = getNewExistentAccount(BigInteger.ONE); + Address addr = getNewExistentAccount(BigInteger.ONE); TRSstateContract trs = newTRSstateContract(addr); byte[] input = new byte[DoubleDataWord.BYTES]; for (int i = Byte.MIN_VALUE; i <= Byte.MAX_VALUE; i++) { if ((i < 0) || (i > MAX_OP)) { input[0] = (byte) i; - assertEquals(PrecompiledResultCode.FAILURE, trs.execute(input, COST).getResultCode()); + assertEquals( + PrecompiledResultCode.FAILURE, trs.execute(input, COST).getResultCode()); } } } @@ -163,10 +166,10 @@ public void testCreatePrecisionTooHigh() { @Test public void testCreateCorrectOwner() { byte[] input = getCreateInput(false, false, 1, BigInteger.ZERO, 0); - AionAddress caller = getNewExistentAccount(BigInteger.ZERO); + Address caller = getNewExistentAccount(BigInteger.ZERO); TRSstateContract trs = newTRSstateContract(caller); PrecompiledTransactionResult res = trs.execute(input, COST); - AionAddress contract = new AionAddress(res.getOutput()); + Address contract = new AionAddress(res.getOutput()); assertEquals(PrecompiledResultCode.SUCCESS, res.getResultCode()); assertEquals(0, res.getEnergyRemaining()); assertEquals(caller, getOwner(trs, contract)); @@ -180,7 +183,7 @@ public void testCreateTestModeCorrectOwner() { byte[] input = getCreateInput(true, false, 1, BigInteger.ZERO, 0); TRSstateContract trs = newTRSstateContract(AION); PrecompiledTransactionResult res = trs.execute(input, COST); - AionAddress contract = AionAddress.wrap(res.getOutput()); + Address contract = AionAddress.wrap(res.getOutput()); assertEquals(PrecompiledResultCode.SUCCESS, res.getResultCode()); assertEquals(0, res.getEnergyRemaining()); assertFalse(isContractLocked(trs, contract)); @@ -193,10 +196,10 @@ public void testCreateVerifyPeriods() { // Test on min periods. int periods = 1; byte[] input = getCreateInput(false, false, periods, BigInteger.ZERO, 0); - AionAddress caller = getNewExistentAccount(BigInteger.ZERO); + Address caller = getNewExistentAccount(BigInteger.ZERO); TRSstateContract trs = newTRSstateContract(caller); PrecompiledTransactionResult res = trs.execute(input, COST); - AionAddress contract = AionAddress.wrap(res.getOutput()); + Address contract = AionAddress.wrap(res.getOutput()); assertEquals(PrecompiledResultCode.SUCCESS, res.getResultCode()); assertEquals(0, res.getEnergyRemaining()); assertEquals(periods, getPeriods(trs, contract)); @@ -227,7 +230,7 @@ public void testCreateTestModeVerifyPeriods() { byte[] input = getCreateInput(true, false, periods, BigInteger.ZERO, 0); TRSstateContract trs = newTRSstateContract(AION); PrecompiledTransactionResult res = trs.execute(input, COST); - AionAddress contract = AionAddress.wrap(res.getOutput()); + Address contract = AionAddress.wrap(res.getOutput()); assertEquals(PrecompiledResultCode.SUCCESS, res.getResultCode()); assertEquals(0, res.getEnergyRemaining()); assertEquals(periods, getPeriods(trs, contract)); @@ -260,10 +263,10 @@ public void testCreateVerifyPeriodsByteBoundary() { int periods3 = 0x1FF; byte[] input = getCreateInput(false, false, periods, BigInteger.ZERO, 0); - AionAddress caller = getNewExistentAccount(BigInteger.ZERO); + Address caller = getNewExistentAccount(BigInteger.ZERO); TRSstateContract trs = newTRSstateContract(caller); PrecompiledTransactionResult res = trs.execute(input, COST); - AionAddress contract = AionAddress.wrap(res.getOutput()); + Address contract = AionAddress.wrap(res.getOutput()); assertEquals(PrecompiledResultCode.SUCCESS, res.getResultCode()); assertEquals(0, res.getEnergyRemaining()); assertEquals(periods, getPeriods(trs, contract)); @@ -305,7 +308,7 @@ public void testCreateVerifyIsTest() { byte[] input = getCreateInput(isTest, false, 1, BigInteger.ZERO, 0); TRSstateContract trs = newTRSstateContract(getNewExistentAccount(BigInteger.ZERO)); PrecompiledTransactionResult res = trs.execute(input, COST); - AionAddress contract = AionAddress.wrap(res.getOutput()); + Address contract = AionAddress.wrap(res.getOutput()); assertEquals(PrecompiledResultCode.SUCCESS, res.getResultCode()); assertEquals(0, res.getEnergyRemaining()); assertEquals(isTest, isTestContract(trs, contract)); @@ -331,11 +334,11 @@ public void testCreateVerifyIsTest() { public void testCreateVerifyIsDirectDeposit() { // When false boolean isDirectDeposit = false; - AionAddress caller = getNewExistentAccount(BigInteger.ZERO); + Address caller = getNewExistentAccount(BigInteger.ZERO); byte[] input = getCreateInput(false, isDirectDeposit, 1, BigInteger.ZERO, 0); TRSstateContract trs = newTRSstateContract(caller); PrecompiledTransactionResult res = trs.execute(input, COST); - AionAddress contract = AionAddress.wrap(res.getOutput()); + Address contract = AionAddress.wrap(res.getOutput()); assertEquals(PrecompiledResultCode.SUCCESS, res.getResultCode()); assertEquals(0, res.getEnergyRemaining()); assertEquals(isDirectDeposit, isDirectDepositEnabled(trs, contract)); @@ -362,11 +365,11 @@ public void testCreateVerifyIsDirectDeposit() { @Test public void testCreateVerifyZeroPercentage() { // Test no shifts. - AionAddress caller = getNewExistentAccount(BigInteger.ZERO); + Address caller = getNewExistentAccount(BigInteger.ZERO); byte[] input = getCreateInput(false, false, 1, BigInteger.ZERO, 0); TRSstateContract trs = newTRSstateContract(caller); PrecompiledTransactionResult res = trs.execute(input, COST); - AionAddress contract = AionAddress.wrap(res.getOutput()); + Address contract = AionAddress.wrap(res.getOutput()); assertEquals(PrecompiledResultCode.SUCCESS, res.getResultCode()); assertEquals(0, res.getEnergyRemaining()); assertEquals(BigDecimal.ZERO, getPercentage(trs, contract)); @@ -393,11 +396,11 @@ public void testCreateVerifyZeroPercentage() { public void testCreateVerifyOneHundredPercentage() { // Test no shifts. BigInteger raw = new BigInteger("100"); - AionAddress caller = getNewExistentAccount(BigInteger.ZERO); + Address caller = getNewExistentAccount(BigInteger.ZERO); byte[] input = getCreateInput(false, false, 1, raw, 0); TRSstateContract trs = newTRSstateContract(caller); PrecompiledTransactionResult res = trs.execute(input, COST); - AionAddress contract = AionAddress.wrap(res.getOutput()); + Address contract = AionAddress.wrap(res.getOutput()); assertEquals(PrecompiledResultCode.SUCCESS, res.getResultCode()); assertEquals(0, res.getEnergyRemaining()); assertEquals(new BigDecimal(raw), getPercentage(trs, contract)); @@ -425,7 +428,7 @@ public void testCreateVerifyOneHundredPercentage() { public void testCreateAboveOneHundredPercentage() { // Test no shifts. BigInteger raw = new BigInteger("101"); - AionAddress caller = getNewExistentAccount(BigInteger.ZERO); + Address caller = getNewExistentAccount(BigInteger.ZERO); byte[] input = getCreateInput(false, false, 1, raw, 0); TRSstateContract trs = newTRSstateContract(caller); PrecompiledTransactionResult res = trs.execute(input, COST); @@ -470,11 +473,11 @@ public void testCreateAboveOneHundredPercentage() { public void testCreateVerify18DecimalPercentage() { // This is: 99.999999999999999999 with 18 shifts ... verify it is ok and we get it back BigInteger raw = new BigInteger("99999999999999999999"); - AionAddress caller = getNewExistentAccount(BigInteger.ZERO); + Address caller = getNewExistentAccount(BigInteger.ZERO); byte[] input = getCreateInput(false, false, 1, raw, 18); TRSstateContract trs = newTRSstateContract(caller); PrecompiledTransactionResult res = trs.execute(input, COST); - AionAddress contract = AionAddress.wrap(res.getOutput()); + Address contract = AionAddress.wrap(res.getOutput()); assertEquals(PrecompiledResultCode.SUCCESS, res.getResultCode()); assertEquals(0, res.getEnergyRemaining()); assertEquals(new BigDecimal(raw).movePointLeft(18), getPercentage(trs, contract)); @@ -520,7 +523,7 @@ public void testCreateValidAndInvalidPercentagesByShifting() { // With no shifting we have: 872743562198734% -> no good int shifts = 0; BigInteger raw = new BigInteger("872743562198734"); - AionAddress caller = getNewExistentAccount(BigInteger.ZERO); + Address caller = getNewExistentAccount(BigInteger.ZERO); byte[] input = getCreateInput(false, false, 1, raw, shifts); TRSstateContract trs = newTRSstateContract(caller); PrecompiledTransactionResult res = trs.execute(input, COST); @@ -540,7 +543,7 @@ public void testCreateValidAndInvalidPercentagesByShifting() { input = getCreateInput(false, false, 1, raw, shifts); trs = newTRSstateContract(caller); res = trs.execute(input, COST); - AionAddress contract = AionAddress.wrap(res.getOutput()); + Address contract = AionAddress.wrap(res.getOutput()); assertEquals(PrecompiledResultCode.SUCCESS, res.getResultCode()); assertEquals(0, res.getEnergyRemaining()); assertEquals(new BigDecimal(raw).movePointLeft(shifts), getPercentage(trs, contract)); @@ -584,11 +587,11 @@ public void testCreateValidAndInvalidPercentagesByShifting() { @Test public void testCreateTRSaddressDeterministic() { // The TRS contract address returned must be deterministic, based on owner's addr + nonce. - AionAddress caller = getNewExistentAccount(BigInteger.ZERO); + Address caller = getNewExistentAccount(BigInteger.ZERO); byte[] input = getCreateInput(false, false, 1, BigInteger.ZERO, 0); TRSstateContract trs = newTRSstateContract(caller); PrecompiledTransactionResult res = trs.execute(input, COST); - AionAddress contract = AionAddress.wrap(res.getOutput()); + Address contract = AionAddress.wrap(res.getOutput()); assertEquals(PrecompiledResultCode.SUCCESS, res.getResultCode()); assertEquals(0, res.getEnergyRemaining()); tempAddrs.add(contract); @@ -638,11 +641,11 @@ public void testCreateTRSaddressDeterministic() { @Test public void testCreateSuccessNrgLeft() { long diff = 540; - AionAddress caller = getNewExistentAccount(BigInteger.ZERO); + Address caller = getNewExistentAccount(BigInteger.ZERO); byte[] input = getCreateInput(false, false, 1, BigInteger.ZERO, 0); TRSstateContract trs = newTRSstateContract(caller); PrecompiledTransactionResult res = trs.execute(input, COST + diff); - AionAddress contract = AionAddress.wrap(res.getOutput()); + Address contract = AionAddress.wrap(res.getOutput()); assertEquals(PrecompiledResultCode.SUCCESS, res.getResultCode()); assertEquals(diff, res.getEnergyRemaining()); tempAddrs.add(contract); @@ -653,7 +656,7 @@ public void testCreateSuccessNrgLeft() { @Test public void testCreateContractHasTimestamp() { - AionAddress caller = getNewExistentAccount(BigInteger.ONE); + Address caller = getNewExistentAccount(BigInteger.ONE); byte[] input = getCreateInput(false, true, 1, BigInteger.ZERO, 0); TRSstateContract trs = newTRSstateContract(caller); @@ -662,7 +665,7 @@ public void testCreateContractHasTimestamp() { long after = TimeUnit.MILLISECONDS.toSeconds(System.currentTimeMillis()); assertEquals(PrecompiledResultCode.SUCCESS, res.getResultCode()); - AionAddress contract = AionAddress.wrap(res.getOutput()); + Address contract = AionAddress.wrap(res.getOutput()); long timestamp = getContractTimestamp(trs, contract); assertTrue(timestamp >= before); @@ -674,7 +677,7 @@ public void testCreateContractHasTimestamp() { @Test public void testLockAddressTooSmall() { // Test on empty address. - AionAddress acct = getNewExistentAccount(BigInteger.ZERO); + Address acct = getNewExistentAccount(BigInteger.ZERO); createTRScontract(acct, false, false, 1, BigInteger.ZERO, 0); byte[] input = new byte[1]; input[0] = (byte) 0x1; @@ -694,11 +697,11 @@ public void testLockAddressTooSmall() { @Test public void testLockAddressTooLarge() { - AionAddress acct = getNewExistentAccount(BigInteger.ZERO); - AionAddress contract = createTRScontract(acct, false, false, 1, BigInteger.ZERO, 0); + Address acct = getNewExistentAccount(BigInteger.ZERO); + Address contract = createTRScontract(acct, false, false, 1, BigInteger.ZERO, 0); byte[] input = new byte[34]; input[0] = (byte) 0x1; - System.arraycopy(contract.toBytes(), 0, input, 1, AionAddress.SIZE); + System.arraycopy(contract.toBytes(), 0, input, 1, Address.SIZE); TRSstateContract trs = newTRSstateContract(acct); PrecompiledTransactionResult res = trs.execute(input, COST); assertEquals(PrecompiledResultCode.FAILURE, res.getResultCode()); @@ -708,8 +711,8 @@ public void testLockAddressTooLarge() { @Test public void testLockNotTRScontractAddress() { // Test attempt to lock a regular account. - AionAddress acct = getNewExistentAccount(BigInteger.ZERO); - AionAddress contract = createTRScontract(acct, false, false, 1, BigInteger.ZERO, 0); + Address acct = getNewExistentAccount(BigInteger.ZERO); + Address contract = createTRScontract(acct, false, false, 1, BigInteger.ZERO, 0); byte[] input = getLockInput(acct); TRSstateContract trs = newTRSstateContract(acct); PrecompiledTransactionResult res = trs.execute(input, COST); @@ -728,8 +731,8 @@ public void testLockNotTRScontractAddress() { @Test public void testLockNotContractOwner() { // Test not in test mode: owner is acct, caller is AION. - AionAddress acct = getNewExistentAccount(BigInteger.ZERO); - AionAddress contract = createTRScontract(acct, false, false, 1, BigInteger.ZERO, 0); + Address acct = getNewExistentAccount(BigInteger.ZERO); + Address contract = createTRScontract(acct, false, false, 1, BigInteger.ZERO, 0); byte[] input = getLockInput(contract); TRSstateContract trs = newTRSstateContract(AION); PrecompiledTransactionResult res = trs.execute(input, COST); @@ -748,8 +751,8 @@ public void testLockNotContractOwner() { @Test public void testLockButContractAlreadyLocked() { // Test not in test mode. - AionAddress acct = getNewExistentAccount(BigInteger.ONE); - AionAddress contract = createTRScontract(acct, false, false, 1, BigInteger.ZERO, 0); + Address acct = getNewExistentAccount(BigInteger.ONE); + Address contract = createTRScontract(acct, false, false, 1, BigInteger.ZERO, 0); AbstractTRS trs = newTRSstateContract(acct); assertFalse(isContractLocked(trs, contract)); @@ -758,7 +761,8 @@ public void testLockButContractAlreadyLocked() { // Deposit into contract so we can lock it. byte[] input = getDepositInput(contract, BigInteger.ONE); assertEquals( - PrecompiledResultCode.SUCCESS, newTRSuseContract(acct).execute(input, COST).getResultCode()); + PrecompiledResultCode.SUCCESS, + newTRSuseContract(acct).execute(input, COST).getResultCode()); input = getLockInput(contract); trs = newTRSstateContract(acct); @@ -780,7 +784,8 @@ public void testLockButContractAlreadyLocked() { // Deposit into contract so we can lock it. input = getDepositInput(contract, BigInteger.ONE); assertEquals( - PrecompiledResultCode.SUCCESS, newTRSuseContract(AION).execute(input, COST).getResultCode()); + PrecompiledResultCode.SUCCESS, + newTRSuseContract(AION).execute(input, COST).getResultCode()); assertFalse(isContractLocked(trs, contract)); assertFalse(isContractLive(trs, contract)); @@ -803,8 +808,8 @@ public void testLockButContractAlreadyLocked() { @Test public void testLockAndVerifyIsLocked() { // Test not in test mode. - AionAddress acct = getNewExistentAccount(BigInteger.ONE); - AionAddress contract = createTRScontract(acct, false, false, 1, BigInteger.ZERO, 0); + Address acct = getNewExistentAccount(BigInteger.ONE); + Address contract = createTRScontract(acct, false, false, 1, BigInteger.ZERO, 0); AbstractTRS trs = newTRSstateContract(acct); assertFalse(isContractLocked(trs, contract)); @@ -813,7 +818,8 @@ public void testLockAndVerifyIsLocked() { // Deposit into contract so we can lock it. byte[] input = getDepositInput(contract, BigInteger.ONE); assertEquals( - PrecompiledResultCode.SUCCESS, newTRSuseContract(acct).execute(input, COST).getResultCode()); + PrecompiledResultCode.SUCCESS, + newTRSuseContract(acct).execute(input, COST).getResultCode()); input = getLockInput(contract); trs = newTRSstateContract(acct); @@ -830,7 +836,8 @@ public void testLockAndVerifyIsLocked() { // Deposit into contract so we can lock it. input = getDepositInput(contract, BigInteger.ONE); assertEquals( - PrecompiledResultCode.SUCCESS, newTRSuseContract(AION).execute(input, COST).getResultCode()); + PrecompiledResultCode.SUCCESS, + newTRSuseContract(AION).execute(input, COST).getResultCode()); assertFalse(isContractLocked(trs, contract)); assertFalse(isContractLive(trs, contract)); @@ -848,8 +855,8 @@ public void testLockAndVerifyIsLocked() { @Test public void testLockButContractIsLive() { // Test not in test mode. - AionAddress acct = getNewExistentAccount(BigInteger.ONE); - AionAddress contract = createAndLockTRScontract(acct, false, false, 1, BigInteger.ZERO, 0); + Address acct = getNewExistentAccount(BigInteger.ONE); + Address contract = createAndLockTRScontract(acct, false, false, 1, BigInteger.ZERO, 0); byte[] input = getStartInput(contract); TRSstateContract trs = newTRSstateContract(acct); @@ -887,8 +894,8 @@ public void testLockButContractIsLive() { @Test public void testLockWithContractBalanceZero() { - AionAddress owner = getNewExistentAccount(BigInteger.ONE); - AionAddress contract = createTRScontract(owner, false, true, 1, BigInteger.ZERO, 0); + Address owner = getNewExistentAccount(BigInteger.ONE); + Address contract = createTRScontract(owner, false, true, 1, BigInteger.ZERO, 0); byte[] input = getLockInput(contract); PrecompiledTransactionResult res = newTRSstateContract(owner).execute(input, COST); AbstractTRS trs = newTRSstateContract(owner); @@ -899,10 +906,12 @@ public void testLockWithContractBalanceZero() { // Now deposit into contract and refund it so we are back at zero and try again. input = getDepositInput(contract, BigInteger.ONE); assertEquals( - PrecompiledResultCode.SUCCESS, newTRSuseContract(owner).execute(input, COST).getResultCode()); + PrecompiledResultCode.SUCCESS, + newTRSuseContract(owner).execute(input, COST).getResultCode()); input = getRefundInput(contract, owner, BigInteger.ONE); assertEquals( - PrecompiledResultCode.SUCCESS, newTRSuseContract(owner).execute(input, COST).getResultCode()); + PrecompiledResultCode.SUCCESS, + newTRSuseContract(owner).execute(input, COST).getResultCode()); input = getLockInput(contract); res = newTRSstateContract(owner).execute(input, COST); @@ -916,7 +925,7 @@ public void testLockWithContractBalanceZero() { @Test public void testStartAddressTooSmall() { // Test on empty address. - AionAddress acct = getNewExistentAccount(BigInteger.ONE); + Address acct = getNewExistentAccount(BigInteger.ONE); createAndLockTRScontract(acct, false, false, 1, BigInteger.ZERO, 0); byte[] input = new byte[1]; input[0] = (byte) 0x1; @@ -936,11 +945,11 @@ public void testStartAddressTooSmall() { @Test public void testStartAddressTooLarge() { - AionAddress acct = getNewExistentAccount(BigInteger.ONE); - AionAddress contract = createAndLockTRScontract(acct, false, false, 1, BigInteger.ZERO, 0); + Address acct = getNewExistentAccount(BigInteger.ONE); + Address contract = createAndLockTRScontract(acct, false, false, 1, BigInteger.ZERO, 0); byte[] input = new byte[34]; input[0] = (byte) 0x1; - System.arraycopy(contract.toBytes(), 0, input, 1, AionAddress.SIZE); + System.arraycopy(contract.toBytes(), 0, input, 1, Address.SIZE); TRSstateContract trs = newTRSstateContract(acct); PrecompiledTransactionResult res = trs.execute(input, COST); assertEquals(PrecompiledResultCode.FAILURE, res.getResultCode()); @@ -950,11 +959,11 @@ public void testStartAddressTooLarge() { @Test public void testStartNotTRScontractAddress() { // Test regular address as a TRS address. - AionAddress acct = getNewExistentAccount(BigInteger.ONE); - AionAddress contract = createAndLockTRScontract(acct, false, false, 1, BigInteger.ZERO, 0); + Address acct = getNewExistentAccount(BigInteger.ONE); + Address contract = createAndLockTRScontract(acct, false, false, 1, BigInteger.ZERO, 0); byte[] input = new byte[33]; input[0] = (byte) 0x1; - System.arraycopy(contract.toBytes(), 0, input, 1, AionAddress.SIZE); + System.arraycopy(contract.toBytes(), 0, input, 1, Address.SIZE); TRSstateContract trs = newTRSstateContract(acct); PrecompiledTransactionResult res = trs.execute(input, COST); assertEquals(PrecompiledResultCode.FAILURE, res.getResultCode()); @@ -974,8 +983,8 @@ public void testStartNotTRScontractAddress() { @Test public void testStartNotContractOwner() { // Test not in test mode: owner is acct, caller is AION. - AionAddress acct = getNewExistentAccount(BigInteger.ONE); - AionAddress contract = createAndLockTRScontract(acct, false, false, 1, BigInteger.ZERO, 0); + Address acct = getNewExistentAccount(BigInteger.ONE); + Address contract = createAndLockTRScontract(acct, false, false, 1, BigInteger.ZERO, 0); byte[] input = getLockInput(contract); TRSstateContract trs = newTRSstateContract(AION); PrecompiledTransactionResult res = trs.execute(input, COST); @@ -994,8 +1003,8 @@ public void testStartNotContractOwner() { @Test public void testStartButContractAlreadyLive() { // Test not in test mode. - AionAddress acct = getNewExistentAccount(BigInteger.ONE); - AionAddress contract = createAndLockTRScontract(acct, false, false, 1, BigInteger.ZERO, 0); + Address acct = getNewExistentAccount(BigInteger.ONE); + Address contract = createAndLockTRScontract(acct, false, false, 1, BigInteger.ZERO, 0); byte[] input = getStartInput(contract); TRSstateContract trs = newTRSstateContract(acct); @@ -1032,8 +1041,8 @@ public void testStartButContractAlreadyLive() { @Test public void testStartButContractNotLocked() { // Test not in test mode. - AionAddress acct = getNewExistentAccount(BigInteger.ZERO); - AionAddress contract = createTRScontract(acct, false, false, 1, BigInteger.ZERO, 0); + Address acct = getNewExistentAccount(BigInteger.ZERO); + Address contract = createTRScontract(acct, false, false, 1, BigInteger.ZERO, 0); AbstractTRS trs = newTRSstateContract(acct); assertFalse(isContractLocked(trs, contract)); @@ -1058,8 +1067,8 @@ public void testStartButContractNotLocked() { @Test public void testStartAndVerifyIsLive() { // Test not in test mode. - AionAddress acct = getNewExistentAccount(BigInteger.ONE); - AionAddress contract = createAndLockTRScontract(acct, false, false, 1, BigInteger.ZERO, 0); + Address acct = getNewExistentAccount(BigInteger.ONE); + Address contract = createAndLockTRScontract(acct, false, false, 1, BigInteger.ZERO, 0); AbstractTRS trs = newTRSstateContract(acct); assertTrue(isContractLocked(trs, contract)); @@ -1091,14 +1100,14 @@ public void testStartAndVerifyIsLive() { @Test public void testBonusBalanceNonExistentContract() { - AionAddress acct = getNewExistentAccount(BigInteger.ONE); + Address acct = getNewExistentAccount(BigInteger.ONE); assertEquals(BigInteger.ZERO, getBonusBalance(newTRSstateContract(acct), acct)); } @Test public void testBonusBalanceOnContractNotYetLive() { - AionAddress acct = getNewExistentAccount(BigInteger.ONE); - AionAddress contract = createTRScontract(acct, false, true, 1, BigInteger.ZERO, 0); + Address acct = getNewExistentAccount(BigInteger.ONE); + Address contract = createTRScontract(acct, false, true, 1, BigInteger.ZERO, 0); // Deposit bonus funds into contract. Until it is live the contract does not see these // funds. @@ -1108,36 +1117,41 @@ public void testBonusBalanceOnContractNotYetLive() { // Now deposit regularly and lock the contract. Again we should still not see the bonus yet. byte[] input = getDepositInput(contract, BigInteger.ONE); assertEquals( - PrecompiledResultCode.SUCCESS, newTRSuseContract(acct).execute(input, COST).getResultCode()); + PrecompiledResultCode.SUCCESS, + newTRSuseContract(acct).execute(input, COST).getResultCode()); input = getLockInput(contract); assertEquals( - PrecompiledResultCode.SUCCESS, newTRSstateContract(acct).execute(input, COST).getResultCode()); + PrecompiledResultCode.SUCCESS, + newTRSstateContract(acct).execute(input, COST).getResultCode()); assertEquals(BigInteger.ZERO, getBonusBalance(newTRSstateContract(acct), contract)); } @Test public void testStartZeroBonusBalance() { - AionAddress acct = getNewExistentAccount(BigInteger.ONE); - AionAddress contract = createTRScontract(acct, false, true, 1, BigInteger.ZERO, 0); + Address acct = getNewExistentAccount(BigInteger.ONE); + Address contract = createTRScontract(acct, false, true, 1, BigInteger.ZERO, 0); // Deposit regularly and lock contract. We have no bonus deposits in. Start contract. byte[] input = getDepositInput(contract, BigInteger.ONE); assertEquals( - PrecompiledResultCode.SUCCESS, newTRSuseContract(acct).execute(input, COST).getResultCode()); + PrecompiledResultCode.SUCCESS, + newTRSuseContract(acct).execute(input, COST).getResultCode()); input = getLockInput(contract); assertEquals( - PrecompiledResultCode.SUCCESS, newTRSstateContract(acct).execute(input, COST).getResultCode()); + PrecompiledResultCode.SUCCESS, + newTRSstateContract(acct).execute(input, COST).getResultCode()); input = getStartInput(contract); assertEquals( - PrecompiledResultCode.SUCCESS, newTRSstateContract(acct).execute(input, COST).getResultCode()); + PrecompiledResultCode.SUCCESS, + newTRSstateContract(acct).execute(input, COST).getResultCode()); assertEquals(BigInteger.ZERO, getBonusBalance(newTRSstateContract(acct), contract)); } @Test public void testStartNonZeroBonusBalance() { - AionAddress acct = getNewExistentAccount(BigInteger.ONE); - AionAddress contract = createTRScontract(acct, false, true, 1, BigInteger.ZERO, 0); + Address acct = getNewExistentAccount(BigInteger.ONE); + Address contract = createTRScontract(acct, false, true, 1, BigInteger.ZERO, 0); BigInteger bonus1 = new BigInteger("23"); BigInteger bonus2 = new BigInteger("346234"); @@ -1148,16 +1162,19 @@ public void testStartNonZeroBonusBalance() { // Deposit regularly and lock contract. We have no bonus deposits in. Start contract. byte[] input = getDepositInput(contract, BigInteger.ONE); assertEquals( - PrecompiledResultCode.SUCCESS, newTRSuseContract(acct).execute(input, COST).getResultCode()); + PrecompiledResultCode.SUCCESS, + newTRSuseContract(acct).execute(input, COST).getResultCode()); input = getLockInput(contract); assertEquals( - PrecompiledResultCode.SUCCESS, newTRSstateContract(acct).execute(input, COST).getResultCode()); + PrecompiledResultCode.SUCCESS, + newTRSstateContract(acct).execute(input, COST).getResultCode()); repo.addBalance(contract, bonus2); // make a bonus deposit. input = getStartInput(contract); assertEquals( - PrecompiledResultCode.SUCCESS, newTRSstateContract(acct).execute(input, COST).getResultCode()); + PrecompiledResultCode.SUCCESS, + newTRSstateContract(acct).execute(input, COST).getResultCode()); repo.addBalance(contract, bonus3); // this deposit should be ignored. @@ -1166,8 +1183,8 @@ public void testStartNonZeroBonusBalance() { @Test public void testStartNonZeroBonusBalanceUsesMultipleRows() { - AionAddress acct = getNewExistentAccount(BigInteger.ONE); - AionAddress contract = createTRScontract(acct, false, true, 1, BigInteger.ZERO, 0); + Address acct = getNewExistentAccount(BigInteger.ONE); + Address contract = createTRScontract(acct, false, true, 1, BigInteger.ZERO, 0); BigInteger bonus = BigInteger.TWO.pow(300); @@ -1176,16 +1193,19 @@ public void testStartNonZeroBonusBalanceUsesMultipleRows() { // Deposit regularly and lock contract. We have no bonus deposits in. Start contract. byte[] input = getDepositInput(contract, BigInteger.ONE); assertEquals( - PrecompiledResultCode.SUCCESS, newTRSuseContract(acct).execute(input, COST).getResultCode()); + PrecompiledResultCode.SUCCESS, + newTRSuseContract(acct).execute(input, COST).getResultCode()); input = getLockInput(contract); assertEquals( - PrecompiledResultCode.SUCCESS, newTRSstateContract(acct).execute(input, COST).getResultCode()); + PrecompiledResultCode.SUCCESS, + newTRSstateContract(acct).execute(input, COST).getResultCode()); repo.addBalance(contract, bonus); // make a bonus deposit. input = getStartInput(contract); assertEquals( - PrecompiledResultCode.SUCCESS, newTRSstateContract(acct).execute(input, COST).getResultCode()); + PrecompiledResultCode.SUCCESS, + newTRSstateContract(acct).execute(input, COST).getResultCode()); repo.addBalance(contract, bonus); // this deposit should be ignored. @@ -1199,12 +1219,13 @@ public void testTotalOwed1() { BigInteger deposit = BigInteger.TWO.pow(300); BigInteger bonus = BigInteger.TWO.pow(222).subtract(BigInteger.ONE); - AionAddress acct = getNewExistentAccount(deposit); - AionAddress contract = createTRScontract(acct, false, true, 1, BigInteger.ZERO, 0); + Address acct = getNewExistentAccount(deposit); + Address contract = createTRScontract(acct, false, true, 1, BigInteger.ZERO, 0); byte[] input = getDepositInput(contract, deposit); assertEquals( - PrecompiledResultCode.SUCCESS, newTRSuseContract(acct).execute(input, COST).getResultCode()); + PrecompiledResultCode.SUCCESS, + newTRSuseContract(acct).execute(input, COST).getResultCode()); repo.addBalance(contract, bonus); lockAndStartContract(contract, acct); @@ -1247,8 +1268,8 @@ public void testTotalOwed3() { @Test public void testOpenFundsInputTooShort() { - AionAddress acct = getNewExistentAccount(BigInteger.TEN); - AionAddress contract = createTRScontract(acct, false, true, 1, BigInteger.ZERO, 0); + Address acct = getNewExistentAccount(BigInteger.TEN); + Address contract = createTRScontract(acct, false, true, 1, BigInteger.ZERO, 0); byte[] input = getOpenFundsInput(contract); byte[] shortInput = Arrays.copyOf(input, input.length - 1); @@ -1259,8 +1280,8 @@ public void testOpenFundsInputTooShort() { @Test public void testOpenFundsInputTooLong() { - AionAddress acct = getNewExistentAccount(BigInteger.TEN); - AionAddress contract = createTRScontract(acct, false, true, 1, BigInteger.ZERO, 0); + Address acct = getNewExistentAccount(BigInteger.TEN); + Address contract = createTRScontract(acct, false, true, 1, BigInteger.ZERO, 0); byte[] input = getOpenFundsInput(contract); byte[] longInput = new byte[input.length + 1]; @@ -1272,9 +1293,9 @@ public void testOpenFundsInputTooLong() { @Test public void testOpenFundsCallerIsNotOwner() { - AionAddress acct = getNewExistentAccount(BigInteger.TEN); - AionAddress other = getNewExistentAccount(BigInteger.TEN); - AionAddress contract = createTRScontract(acct, false, true, 1, BigInteger.ZERO, 0); + Address acct = getNewExistentAccount(BigInteger.TEN); + Address other = getNewExistentAccount(BigInteger.TEN); + Address contract = createTRScontract(acct, false, true, 1, BigInteger.ZERO, 0); byte[] input = getOpenFundsInput(contract); assertEquals( @@ -1284,8 +1305,8 @@ public void testOpenFundsCallerIsNotOwner() { @Test public void testOpenFundsContractIsLive() { - AionAddress acct = getNewExistentAccount(BigInteger.TEN); - AionAddress contract = createLockedAndLiveTRScontract(acct, false, true, 1, BigInteger.ZERO, 0); + Address acct = getNewExistentAccount(BigInteger.TEN); + Address contract = createLockedAndLiveTRScontract(acct, false, true, 1, BigInteger.ZERO, 0); byte[] input = getOpenFundsInput(contract); assertEquals( @@ -1295,7 +1316,7 @@ public void testOpenFundsContractIsLive() { @Test public void testOpenFundsContractNonExistent() { - AionAddress acct = getNewExistentAccount(BigInteger.TEN); + Address acct = getNewExistentAccount(BigInteger.TEN); byte[] input = getOpenFundsInput(acct); assertEquals( PrecompiledResultCode.FAILURE, @@ -1304,8 +1325,8 @@ public void testOpenFundsContractNonExistent() { @Test public void testOpenFundsContractNotYetLocked() { - AionAddress acct = getNewExistentAccount(BigInteger.TEN); - AionAddress contract = createTRScontract(acct, false, true, 1, BigInteger.ZERO, 0); + Address acct = getNewExistentAccount(BigInteger.TEN); + Address contract = createTRScontract(acct, false, true, 1, BigInteger.ZERO, 0); AbstractTRS trs = newTRSstateContract(acct); byte[] input = getOpenFundsInput(contract); @@ -1315,8 +1336,8 @@ public void testOpenFundsContractNotYetLocked() { @Test public void testOpenFundsContractLockedNotYetLive() { - AionAddress acct = getNewExistentAccount(BigInteger.TEN); - AionAddress contract = createAndLockTRScontract(acct, false, true, 1, BigInteger.ZERO, 0); + Address acct = getNewExistentAccount(BigInteger.TEN); + Address contract = createAndLockTRScontract(acct, false, true, 1, BigInteger.ZERO, 0); AbstractTRS trs = newTRSstateContract(acct); assertFalse(getAreContractFundsOpen(trs, contract)); @@ -1333,11 +1354,12 @@ public void testOpenFundsContractLockedNotYetLive() { @Test public void testOpenFundsMultipleTimes() { // Currently any subsequent attempts are thwarted. - AionAddress acct = getNewExistentAccount(BigInteger.TEN); - AionAddress contract = createTRScontract(acct, false, true, 1, BigInteger.ZERO, 0); + Address acct = getNewExistentAccount(BigInteger.TEN); + Address contract = createTRScontract(acct, false, true, 1, BigInteger.ZERO, 0); byte[] input = getOpenFundsInput(contract); assertEquals( - PrecompiledResultCode.SUCCESS, newTRSstateContract(acct).execute(input, COST).getResultCode()); + PrecompiledResultCode.SUCCESS, + newTRSstateContract(acct).execute(input, COST).getResultCode()); assertEquals( PrecompiledResultCode.FAILURE, newTRSstateContract(acct).execute(input, COST).getResultCode()); @@ -1353,20 +1375,23 @@ public void testOpenFundsWithdrawIsNowWithdrawAll() { BigInteger bal2 = new BigInteger("438756347565782346578"); BigInteger bal3 = new BigInteger("98124329685948546"); BigInteger bonus = new BigInteger("325467523673432535248233278324346"); - AionAddress acct1 = getNewExistentAccount(bal1); - AionAddress acct2 = getNewExistentAccount(bal2); - AionAddress acct3 = getNewExistentAccount(bal3); - AionAddress contract = createTRScontract(acct1, false, true, 100, BigInteger.ZERO, 0); + Address acct1 = getNewExistentAccount(bal1); + Address acct2 = getNewExistentAccount(bal2); + Address acct3 = getNewExistentAccount(bal3); + Address contract = createTRScontract(acct1, false, true, 100, BigInteger.ZERO, 0); byte[] input = getDepositInput(contract, bal1); assertEquals( - PrecompiledResultCode.SUCCESS, newTRSuseContract(acct1).execute(input, COST).getResultCode()); + PrecompiledResultCode.SUCCESS, + newTRSuseContract(acct1).execute(input, COST).getResultCode()); input = getDepositInput(contract, bal2); assertEquals( - PrecompiledResultCode.SUCCESS, newTRSuseContract(acct2).execute(input, COST).getResultCode()); + PrecompiledResultCode.SUCCESS, + newTRSuseContract(acct2).execute(input, COST).getResultCode()); input = getDepositInput(contract, bal3); assertEquals( - PrecompiledResultCode.SUCCESS, newTRSuseContract(acct3).execute(input, COST).getResultCode()); + PrecompiledResultCode.SUCCESS, + newTRSuseContract(acct3).execute(input, COST).getResultCode()); repo.addBalance(contract, bonus); assertEquals(BigInteger.ZERO, repo.getBalance(acct1)); assertEquals(BigInteger.ZERO, repo.getBalance(acct2)); @@ -1385,11 +1410,14 @@ public void testOpenFundsWithdrawIsNowWithdrawAll() { BigInteger owings3 = grabOwings(new BigDecimal(bal3), total, new BigDecimal(bonus)); input = getWithdrawInput(contract); assertEquals( - PrecompiledResultCode.SUCCESS, newTRSuseContract(acct1).execute(input, COST).getResultCode()); + PrecompiledResultCode.SUCCESS, + newTRSuseContract(acct1).execute(input, COST).getResultCode()); assertEquals( - PrecompiledResultCode.SUCCESS, newTRSuseContract(acct2).execute(input, COST).getResultCode()); + PrecompiledResultCode.SUCCESS, + newTRSuseContract(acct2).execute(input, COST).getResultCode()); assertEquals( - PrecompiledResultCode.SUCCESS, newTRSuseContract(acct3).execute(input, COST).getResultCode()); + PrecompiledResultCode.SUCCESS, + newTRSuseContract(acct3).execute(input, COST).getResultCode()); assertEquals(owings1, repo.getBalance(acct1)); assertEquals(owings2, repo.getBalance(acct2)); assertEquals(owings3, repo.getBalance(acct3)); @@ -1416,20 +1444,23 @@ public void testOpenFundsBulkWithdrawIsNowBulkWithdrawAll() { BigInteger bal2 = new BigInteger("5454757853"); BigInteger bal3 = new BigInteger("43534654754342"); BigInteger bonus = new BigInteger("546547542332523534"); - AionAddress acct1 = getNewExistentAccount(bal1); - AionAddress acct2 = getNewExistentAccount(bal2); - AionAddress acct3 = getNewExistentAccount(bal3); - AionAddress contract = createTRScontract(acct1, false, true, 100, BigInteger.ZERO, 0); + Address acct1 = getNewExistentAccount(bal1); + Address acct2 = getNewExistentAccount(bal2); + Address acct3 = getNewExistentAccount(bal3); + Address contract = createTRScontract(acct1, false, true, 100, BigInteger.ZERO, 0); byte[] input = getDepositInput(contract, bal1); assertEquals( - PrecompiledResultCode.SUCCESS, newTRSuseContract(acct1).execute(input, COST).getResultCode()); + PrecompiledResultCode.SUCCESS, + newTRSuseContract(acct1).execute(input, COST).getResultCode()); input = getDepositInput(contract, bal2); assertEquals( - PrecompiledResultCode.SUCCESS, newTRSuseContract(acct2).execute(input, COST).getResultCode()); + PrecompiledResultCode.SUCCESS, + newTRSuseContract(acct2).execute(input, COST).getResultCode()); input = getDepositInput(contract, bal3); assertEquals( - PrecompiledResultCode.SUCCESS, newTRSuseContract(acct3).execute(input, COST).getResultCode()); + PrecompiledResultCode.SUCCESS, + newTRSuseContract(acct3).execute(input, COST).getResultCode()); repo.addBalance(contract, bonus); assertEquals(BigInteger.ZERO, repo.getBalance(acct1)); assertEquals(BigInteger.ZERO, repo.getBalance(acct2)); @@ -1448,14 +1479,16 @@ public void testOpenFundsBulkWithdrawIsNowBulkWithdrawAll() { BigInteger owings3 = grabOwings(new BigDecimal(bal3), total, new BigDecimal(bonus)); input = getBulkWithdrawInput(contract); assertEquals( - PrecompiledResultCode.SUCCESS, newTRSuseContract(acct1).execute(input, COST).getResultCode()); + PrecompiledResultCode.SUCCESS, + newTRSuseContract(acct1).execute(input, COST).getResultCode()); assertEquals(owings1, repo.getBalance(acct1)); assertEquals(owings2, repo.getBalance(acct2)); assertEquals(owings3, repo.getBalance(acct3)); // A subsequent withdraw operation should not withdraw anything now. assertEquals( - PrecompiledResultCode.SUCCESS, newTRSuseContract(acct1).execute(input, COST).getResultCode()); + PrecompiledResultCode.SUCCESS, + newTRSuseContract(acct1).execute(input, COST).getResultCode()); assertEquals(owings1, repo.getBalance(acct1)); assertEquals(owings2, repo.getBalance(acct2)); assertEquals(owings3, repo.getBalance(acct3)); @@ -1463,8 +1496,8 @@ public void testOpenFundsBulkWithdrawIsNowBulkWithdrawAll() { @Test public void testOpenFundsLockContractNowDisabled() { - AionAddress acct = getNewExistentAccount(BigInteger.TEN); - AionAddress contract = createTRScontract(acct, false, true, 1, BigInteger.ZERO, 0); + Address acct = getNewExistentAccount(BigInteger.TEN); + Address contract = createTRScontract(acct, false, true, 1, BigInteger.ZERO, 0); AbstractTRS trs = newTRSstateContract(acct); byte[] input = getOpenFundsInput(contract); @@ -1479,8 +1512,8 @@ public void testOpenFundsLockContractNowDisabled() { @Test public void testOpenFundsStartContractNowDisabled() { - AionAddress acct = getNewExistentAccount(BigInteger.TEN); - AionAddress contract = createAndLockTRScontract(acct, false, true, 1, BigInteger.ZERO, 0); + Address acct = getNewExistentAccount(BigInteger.TEN); + Address contract = createAndLockTRScontract(acct, false, true, 1, BigInteger.ZERO, 0); AbstractTRS trs = newTRSstateContract(acct); byte[] input = getOpenFundsInput(contract); @@ -1495,8 +1528,8 @@ public void testOpenFundsStartContractNowDisabled() { @Test public void testOpenFundsIsLockedAndIsLive() { - AionAddress acct = getNewExistentAccount(BigInteger.TEN); - AionAddress contract = createTRScontract(acct, false, true, 1, BigInteger.ZERO, 0); + Address acct = getNewExistentAccount(BigInteger.TEN); + Address contract = createTRScontract(acct, false, true, 1, BigInteger.ZERO, 0); AbstractTRS trs = newTRSstateContract(acct); byte[] input = getOpenFundsInput(contract); @@ -1516,8 +1549,8 @@ public void testOpenFundsIsLockedAndIsLive() { @Test public void testOpenFundsNoFundsWithdraw() { - AionAddress acct = getNewExistentAccount(BigInteger.TEN); - AionAddress contract = createTRScontract(acct, false, true, 10, BigInteger.ZERO, 0); + Address acct = getNewExistentAccount(BigInteger.TEN); + Address contract = createTRScontract(acct, false, true, 10, BigInteger.ZERO, 0); AbstractTRS trs = newTRSstateContract(acct); byte[] input = getOpenFundsInput(contract); @@ -1534,8 +1567,8 @@ public void testOpenFundsNoFundsWithdraw() { @Test public void testOpenFundsDepositNowDisabled() { - AionAddress acct = getNewExistentAccount(BigInteger.TEN); - AionAddress contract = createTRScontract(acct, false, true, 10, BigInteger.ZERO, 0); + Address acct = getNewExistentAccount(BigInteger.TEN); + Address contract = createTRScontract(acct, false, true, 10, BigInteger.ZERO, 0); AbstractTRS trs = newTRSstateContract(acct); byte[] input = getOpenFundsInput(contract); @@ -1553,9 +1586,9 @@ public void testOpenFundsDepositNowDisabled() { @Test public void testOpenFundsDepositForNowDisabled() { - AionAddress acct = getNewExistentAccount(BigInteger.TEN); - AionAddress other = getNewExistentAccount(BigInteger.ZERO); - AionAddress contract = createTRScontract(acct, false, true, 10, BigInteger.ZERO, 0); + Address acct = getNewExistentAccount(BigInteger.TEN); + Address other = getNewExistentAccount(BigInteger.ZERO); + Address contract = createTRScontract(acct, false, true, 10, BigInteger.ZERO, 0); AbstractTRS trs = newTRSstateContract(acct); byte[] input = getOpenFundsInput(contract); @@ -1573,8 +1606,8 @@ public void testOpenFundsDepositForNowDisabled() { @Test public void testOpenFundsBulkDepositForNowDisabled() { - AionAddress owner = getNewExistentAccount(BigInteger.ZERO); - AionAddress contract = createTRScontract(owner, false, true, 1, BigInteger.ZERO, 0); + Address owner = getNewExistentAccount(BigInteger.ZERO); + Address contract = createTRScontract(owner, false, true, 1, BigInteger.ZERO, 0); // Open all funds. byte[] input = getOpenFundsInput(contract); @@ -1585,7 +1618,7 @@ public void testOpenFundsBulkDepositForNowDisabled() { // Now attempt to do a bulk deposit. int numBeneficiaries = 2; BigInteger deposit = new BigInteger("239785623"); - AionAddress[] beneficiaries = new AionAddress[numBeneficiaries]; + Address[] beneficiaries = new Address[numBeneficiaries]; BigInteger[] amounts = new BigInteger[numBeneficiaries]; for (int i = 0; i < numBeneficiaries; i++) { beneficiaries[i] = getNewExistentAccount(BigInteger.ZERO); @@ -1597,21 +1630,22 @@ public void testOpenFundsBulkDepositForNowDisabled() { repo.addBalance(owner, total); input = getBulkDepositForInput(contract, beneficiaries, amounts); assertEquals(PrecompiledResultCode.FAILURE, trs.execute(input, COST).getResultCode()); - for (AionAddress acc : beneficiaries) { + for (Address acc : beneficiaries) { assertEquals(BigInteger.ZERO, getDepositBalance(trs, contract, acc)); } } @Test public void testOpenFundsRefundNowDisabled() { - AionAddress acct = getNewExistentAccount(BigInteger.TEN); - AionAddress other = getNewExistentAccount(BigInteger.ONE); - AionAddress contract = createTRScontract(acct, false, true, 10, BigInteger.ZERO, 0); + Address acct = getNewExistentAccount(BigInteger.TEN); + Address other = getNewExistentAccount(BigInteger.ONE); + Address contract = createTRScontract(acct, false, true, 10, BigInteger.ZERO, 0); AbstractTRS trs = newTRSstateContract(acct); byte[] input = getDepositInput(contract, BigInteger.ONE); assertEquals( - PrecompiledResultCode.SUCCESS, newTRSuseContract(other).execute(input, COST).getResultCode()); + PrecompiledResultCode.SUCCESS, + newTRSuseContract(other).execute(input, COST).getResultCode()); assertEquals(BigInteger.ONE, getDepositBalance(trs, contract, other)); assertEquals(BigInteger.ZERO, repo.getBalance(other)); @@ -1630,8 +1664,8 @@ public void testOpenFundsRefundNowDisabled() { @Test public void testOpenFundsAddExtraNowDisabled() { - AionAddress acct = getNewExistentAccount(BigInteger.TEN); - AionAddress contract = createTRScontract(acct, false, true, 8, BigInteger.ZERO, 0); + Address acct = getNewExistentAccount(BigInteger.TEN); + Address contract = createTRScontract(acct, false, true, 8, BigInteger.ZERO, 0); AbstractTRS trs = newTRSstateContract(acct); byte[] input = getOpenFundsInput(contract); @@ -1661,16 +1695,18 @@ public void testOpenFundsAddExtraNowDisabled() { */ private void checkOwingsGivenDepositsAndBonus( BigInteger deposit1, BigInteger deposit2, BigInteger bonus) { - AionAddress acct1 = getNewExistentAccount(deposit1); - AionAddress acct2 = getNewExistentAccount(deposit2); - AionAddress contract = createTRScontract(acct1, false, true, 1, BigInteger.ZERO, 0); + Address acct1 = getNewExistentAccount(deposit1); + Address acct2 = getNewExistentAccount(deposit2); + Address contract = createTRScontract(acct1, false, true, 1, BigInteger.ZERO, 0); byte[] input = getDepositInput(contract, deposit1); assertEquals( - PrecompiledResultCode.SUCCESS, newTRSuseContract(acct1).execute(input, COST).getResultCode()); + PrecompiledResultCode.SUCCESS, + newTRSuseContract(acct1).execute(input, COST).getResultCode()); input = getDepositInput(contract, deposit2); assertEquals( - PrecompiledResultCode.SUCCESS, newTRSuseContract(acct2).execute(input, COST).getResultCode()); + PrecompiledResultCode.SUCCESS, + newTRSuseContract(acct2).execute(input, COST).getResultCode()); repo.addBalance(contract, bonus); lockAndStartContract(contract, acct1); @@ -1766,20 +1802,23 @@ private void checkOwings(int frac) { BigInteger bonus = BigInteger.TWO.pow(56); // Actually perform the deposits and then do checks. - AionAddress acct = getNewExistentAccount(deposit); - AionAddress acct1 = getNewExistentAccount(deposit1); - AionAddress acct2 = getNewExistentAccount(deposit2); - AionAddress contract = createTRScontract(acct, false, true, 1, BigInteger.ZERO, 0); + Address acct = getNewExistentAccount(deposit); + Address acct1 = getNewExistentAccount(deposit1); + Address acct2 = getNewExistentAccount(deposit2); + Address contract = createTRScontract(acct, false, true, 1, BigInteger.ZERO, 0); byte[] input = getDepositInput(contract, deposit); assertEquals( - PrecompiledResultCode.SUCCESS, newTRSuseContract(acct).execute(input, COST).getResultCode()); + PrecompiledResultCode.SUCCESS, + newTRSuseContract(acct).execute(input, COST).getResultCode()); input = getDepositInput(contract, deposit1); assertEquals( - PrecompiledResultCode.SUCCESS, newTRSuseContract(acct1).execute(input, COST).getResultCode()); + PrecompiledResultCode.SUCCESS, + newTRSuseContract(acct1).execute(input, COST).getResultCode()); input = getDepositInput(contract, deposit2); assertEquals( - PrecompiledResultCode.SUCCESS, newTRSuseContract(acct2).execute(input, COST).getResultCode()); + PrecompiledResultCode.SUCCESS, + newTRSuseContract(acct2).execute(input, COST).getResultCode()); repo.addBalance(contract, bonus); lockAndStartContract(contract, acct); diff --git a/modPrecompiled/test/org/aion/precompiled/TRS/TRSuseContractTest.java b/modPrecompiled/test/org/aion/precompiled/TRS/TRSuseContractTest.java index 25a1ff8e28..6ee288676a 100644 --- a/modPrecompiled/test/org/aion/precompiled/TRS/TRSuseContractTest.java +++ b/modPrecompiled/test/org/aion/precompiled/TRS/TRSuseContractTest.java @@ -12,15 +12,16 @@ import java.util.Arrays; import java.util.Set; import org.aion.base.type.AionAddress; -import org.aion.precompiled.PrecompiledResultCode; -import org.aion.precompiled.PrecompiledTransactionResult; import org.aion.base.util.ByteUtil; import org.aion.crypto.ECKeyFac; import org.aion.mcf.vm.types.DoubleDataWord; +import org.aion.precompiled.PrecompiledResultCode; +import org.aion.precompiled.PrecompiledTransactionResult; import org.aion.precompiled.contracts.DummyRepo; import org.aion.precompiled.contracts.TRS.AbstractTRS; import org.aion.precompiled.contracts.TRS.TRSuseContract; import org.aion.precompiled.type.StatefulPrecompiledContract; +import org.aion.vm.api.interfaces.Address; import org.junit.After; import org.junit.Before; import org.junit.Test; @@ -39,7 +40,7 @@ public void setup() { @After public void tearDown() { - for (AionAddress acct : tempAddrs) { + for (Address acct : tempAddrs) { repo.deleteAccount(acct); } tempAddrs = null; @@ -71,7 +72,7 @@ public void testCreateEmptyInput() { @Test public void testInsufficientNrg() { - AionAddress addr = getNewExistentAccount(BigInteger.ZERO); + Address addr = getNewExistentAccount(BigInteger.ZERO); TRSuseContract trs = newTRSuseContract(addr); byte[] input = getDepositInput(addr, BigInteger.ZERO); PrecompiledTransactionResult res; @@ -84,7 +85,7 @@ public void testInsufficientNrg() { @Test public void testTooMuchNrg() { - AionAddress addr = getNewExistentAccount(BigInteger.ZERO); + Address addr = getNewExistentAccount(BigInteger.ZERO); TRSuseContract trs = newTRSuseContract(addr); byte[] input = getDepositInput(addr, BigInteger.ZERO); PrecompiledTransactionResult res; @@ -97,13 +98,14 @@ public void testTooMuchNrg() { @Test public void testInvalidOperation() { - AionAddress addr = getNewExistentAccount(BigInteger.ONE); + Address addr = getNewExistentAccount(BigInteger.ONE); TRSuseContract trs = newTRSuseContract(addr); byte[] input = new byte[DoubleDataWord.BYTES]; for (int i = Byte.MIN_VALUE; i <= Byte.MAX_VALUE; i++) { if ((i < 0) || (i > MAX_OP)) { input[0] = (byte) i; - assertEquals(PrecompiledResultCode.FAILURE, trs.execute(input, COST).getResultCode()); + assertEquals( + PrecompiledResultCode.FAILURE, trs.execute(input, COST).getResultCode()); } } } @@ -138,7 +140,7 @@ public void testDepositInputTooLong() { @Test public void testDepositToNonExistentContract() { // Test on contract address actually an account address. - AionAddress acct = getNewExistentAccount(DEFAULT_BALANCE); + Address acct = getNewExistentAccount(DEFAULT_BALANCE); TRSuseContract trs = newTRSuseContract(acct); byte[] input = getDepositInput(acct, BigInteger.TWO); PrecompiledTransactionResult res = trs.execute(input, COST); @@ -146,8 +148,8 @@ public void testDepositToNonExistentContract() { assertEquals(0, res.getEnergyRemaining()); // Test on contract address looks like a legit TRS address (proper prefix). - byte[] addr = new byte[AionAddress.SIZE]; - System.arraycopy(acct.toBytes(), 0, addr, 0, AionAddress.SIZE); + byte[] addr = new byte[Address.SIZE]; + System.arraycopy(acct.toBytes(), 0, addr, 0, Address.SIZE); addr[0] = (byte) 0xC0; input = getDepositInput(AionAddress.wrap(addr), BigInteger.TWO); @@ -160,9 +162,9 @@ public void testDepositToNonExistentContract() { public void testDepositInsufficientBalance() { // Test not in test mode. // Test on minimum too-large amount. - AionAddress acct = getNewExistentAccount(DEFAULT_BALANCE); + Address acct = getNewExistentAccount(DEFAULT_BALANCE); TRSuseContract trs = newTRSuseContract(acct); - AionAddress contract = createTRScontract(acct, false, true, 1, BigInteger.ZERO, 0); + Address contract = createTRScontract(acct, false, true, 1, BigInteger.ZERO, 0); byte[] input = getDepositInput(contract, DEFAULT_BALANCE.add(BigInteger.ONE)); PrecompiledTransactionResult res = trs.execute(input, COST); @@ -192,9 +194,9 @@ public void testDepositInsufficientBalance() { @Test public void testDepositDirectDepositsDisabledCallerIsOwner() { - AionAddress acct = getNewExistentAccount(DEFAULT_BALANCE); + Address acct = getNewExistentAccount(DEFAULT_BALANCE); TRSuseContract trs = newTRSuseContract(acct); - AionAddress contract = createTRScontract(acct, false, false, 1, BigInteger.ZERO, 0); + Address contract = createTRScontract(acct, false, false, 1, BigInteger.ZERO, 0); byte[] input = getDepositInput(contract, BigInteger.TWO); PrecompiledTransactionResult res = trs.execute(input, COST); @@ -205,9 +207,9 @@ public void testDepositDirectDepositsDisabledCallerIsOwner() { @Test public void testDepositDirectDepositsDisabledCallerNotOwner() { - AionAddress acct = getNewExistentAccount(DEFAULT_BALANCE); - AionAddress owner = getNewExistentAccount(BigInteger.ZERO); - AionAddress contract = createTRScontract(owner, false, false, 1, BigInteger.ZERO, 0); + Address acct = getNewExistentAccount(DEFAULT_BALANCE); + Address owner = getNewExistentAccount(BigInteger.ZERO); + Address contract = createTRScontract(owner, false, false, 1, BigInteger.ZERO, 0); TRSuseContract trs = newTRSuseContract(acct); byte[] input = getDepositInput(contract, BigInteger.TWO); @@ -218,8 +220,8 @@ public void testDepositDirectDepositsDisabledCallerNotOwner() { @Test public void testDepositCallerIsContract() { - AionAddress acct = getNewExistentAccount(DEFAULT_BALANCE); - AionAddress contract = createTRScontract(acct, false, false, 1, BigInteger.ZERO, 0); + Address acct = getNewExistentAccount(DEFAULT_BALANCE); + Address contract = createTRScontract(acct, false, false, 1, BigInteger.ZERO, 0); TRSuseContract trs = newTRSuseContract(contract); byte[] input = getDepositInput(contract, BigInteger.TWO); @@ -231,9 +233,9 @@ public void testDepositCallerIsContract() { @Test public void testDepositZero() { // Test zero deposit with zero balance. - AionAddress acct = getNewExistentAccount(BigInteger.ZERO); + Address acct = getNewExistentAccount(BigInteger.ZERO); TRSuseContract trs = newTRSuseContract(acct); - AionAddress contract = createTRScontract(acct, false, true, 1, BigInteger.ZERO, 0); + Address contract = createTRScontract(acct, false, true, 1, BigInteger.ZERO, 0); byte[] input = getDepositInput(contract, BigInteger.ZERO); PrecompiledTransactionResult res = trs.execute(input, COST); @@ -258,9 +260,9 @@ public void testDepositZero() { @Test public void testDepositOne() { // Test deposit with one balance. - AionAddress acct = getNewExistentAccount(BigInteger.ONE); + Address acct = getNewExistentAccount(BigInteger.ONE); TRSuseContract trs = newTRSuseContract(acct); - AionAddress contract = createTRScontract(acct, false, true, 1, BigInteger.ZERO, 0); + Address contract = createTRScontract(acct, false, true, 1, BigInteger.ZERO, 0); byte[] input = getDepositInput(contract, BigInteger.ONE); PrecompiledTransactionResult res = trs.execute(input, COST); @@ -288,9 +290,9 @@ public void testDepositOne() { @Test public void testDepositFullBalance() { - AionAddress acct = getNewExistentAccount(DEFAULT_BALANCE); + Address acct = getNewExistentAccount(DEFAULT_BALANCE); TRSuseContract trs = newTRSuseContract(acct); - AionAddress contract = createTRScontract(acct, false, true, 1, BigInteger.ZERO, 0); + Address contract = createTRScontract(acct, false, true, 1, BigInteger.ZERO, 0); byte[] input = getDepositInput(contract, DEFAULT_BALANCE); PrecompiledTransactionResult res = trs.execute(input, COST); @@ -320,9 +322,9 @@ public void testDepositFullBalance() { @Test public void testDepositMaxOneTimeAmount() { BigInteger max = getMaxOneTimeDeposit(); - AionAddress acct = getNewExistentAccount(max.add(DEFAULT_BALANCE)); + Address acct = getNewExistentAccount(max.add(DEFAULT_BALANCE)); TRSuseContract trs = newTRSuseContract(acct); - AionAddress contract = createTRScontract(acct, false, true, 1, BigInteger.ZERO, 0); + Address contract = createTRScontract(acct, false, true, 1, BigInteger.ZERO, 0); byte[] input = getMaxDepositInput(contract); PrecompiledTransactionResult res = trs.execute(input, COST); @@ -337,9 +339,9 @@ public void testDepositMaxOneTimeAmount() { @Test public void testDepositMultipleTimes() { BigInteger max = getMaxOneTimeDeposit(); - AionAddress acct = getNewExistentAccount(max); + Address acct = getNewExistentAccount(max); TRSuseContract trs = newTRSuseContract(acct); - AionAddress contract = createTRScontract(acct, false, true, 1, BigInteger.ZERO, 0); + Address contract = createTRScontract(acct, false, true, 1, BigInteger.ZERO, 0); BigInteger amt = new BigInteger("123456"); BigInteger left = max; @@ -364,9 +366,9 @@ public void testDepositMaxMultipleTimes() { // maximum but we can still hit it a good number of times. BigInteger maxTotal = getMaxTotalDeposit(); BigInteger max = getMaxOneTimeDeposit(); - AionAddress acct = getNewExistentAccount(maxTotal); + Address acct = getNewExistentAccount(maxTotal); TRSuseContract trs = newTRSuseContract(acct); - AionAddress contract = createTRScontract(acct, false, true, 1, BigInteger.ZERO, 0); + Address contract = createTRScontract(acct, false, true, 1, BigInteger.ZERO, 0); BigInteger left = maxTotal; BigInteger depo = BigInteger.ZERO; @@ -387,9 +389,9 @@ public void testDepositMaxMultipleTimes() { @Test public void testDepositMultipleDepositors() { BigInteger max = getMaxOneTimeDeposit(); - AionAddress acct1 = getNewExistentAccount(max); - AionAddress acct2 = getNewExistentAccount(max); - AionAddress acct3 = getNewExistentAccount(max); + Address acct1 = getNewExistentAccount(max); + Address acct2 = getNewExistentAccount(max); + Address acct3 = getNewExistentAccount(max); BigInteger acct1Bal = max; BigInteger acct2Bal = max; BigInteger acct3Bal = max; @@ -397,7 +399,7 @@ public void testDepositMultipleDepositors() { BigInteger acct2Depo = BigInteger.ZERO; BigInteger acct3Depo = BigInteger.ZERO; - AionAddress contract = createTRScontract(acct1, false, true, 1, BigInteger.ZERO, 0); + Address contract = createTRScontract(acct1, false, true, 1, BigInteger.ZERO, 0); BigInteger amt1 = new BigInteger("123456"); BigInteger amt2 = new BigInteger("4363123"); BigInteger amt3 = new BigInteger("8597455434"); @@ -435,9 +437,9 @@ public void testDepositMultipleDepositors() { public void testDepositThatCausesOverflow() { // First we deposit 2**31 - 1 and then deposit 1 to overflow into next row. BigInteger total = BigInteger.TWO.pow(255); - AionAddress acct = getNewExistentAccount(total); + Address acct = getNewExistentAccount(total); BigInteger amount = total.subtract(BigInteger.ONE); - AionAddress contract = createTRScontract(acct, false, true, 1, BigInteger.ZERO, 0); + Address contract = createTRScontract(acct, false, true, 1, BigInteger.ZERO, 0); TRSuseContract trs = newTRSuseContract(acct); byte[] input = getDepositInput(contract, amount); trs.execute(input, COST); @@ -470,33 +472,35 @@ public void testDepositThatCausesOverflow() { @Test public void testDepositNumRowsWhenAllRowsFull() { BigInteger total = BigInteger.TWO.pow(255); - AionAddress acct = getNewExistentAccount(total); - AionAddress contract = createTRScontract(acct, false, true, 1, BigInteger.ZERO, 0); + Address acct = getNewExistentAccount(total); + Address contract = createTRScontract(acct, false, true, 1, BigInteger.ZERO, 0); TRSuseContract trs = newTRSuseContract(acct); byte[] input = getDepositInput(contract, total); trs.execute(input, COST); - int rows = repo.getStorageValue(contract, newDataWordStub(acct.toBytes())).getData()[0] & 0x0F; + int rows = + repo.getStorageValue(contract, newDataWordStub(acct.toBytes())).getData()[0] & 0x0F; assertEquals(1, rows); } @Test public void testDepositNumRowsWhenOneRowHasOneNonZeroByte() { BigInteger total = BigInteger.TWO.pow(256); - AionAddress acct = getNewExistentAccount(total); - AionAddress contract = createTRScontract(acct, false, true, 1, BigInteger.ZERO, 0); + Address acct = getNewExistentAccount(total); + Address contract = createTRScontract(acct, false, true, 1, BigInteger.ZERO, 0); TRSuseContract trs = newTRSuseContract(acct); byte[] input = getDepositInput(contract, total); trs.execute(input, COST); - int rows = repo.getStorageValue(contract, newDataWordStub(acct.toBytes())).getData()[0] & 0x0F; + int rows = + repo.getStorageValue(contract, newDataWordStub(acct.toBytes())).getData()[0] & 0x0F; assertEquals(2, rows); } @Test public void testDepositWhileTRSisLocked() { - AionAddress acct = getNewExistentAccount(DEFAULT_BALANCE); - AionAddress contract = createAndLockTRScontract(acct, false, true, 1, BigInteger.ZERO, 0); + Address acct = getNewExistentAccount(DEFAULT_BALANCE); + Address contract = createAndLockTRScontract(acct, false, true, 1, BigInteger.ZERO, 0); TRSuseContract trs = newTRSuseContract(acct); byte[] input = getDepositInput(contract, BigInteger.ONE); PrecompiledTransactionResult res = trs.execute(input, COST); @@ -506,8 +510,8 @@ public void testDepositWhileTRSisLocked() { @Test public void testDepositWhileTRSisLive() { - AionAddress acct = getNewExistentAccount(DEFAULT_BALANCE); - AionAddress contract = createLockedAndLiveTRScontract(acct, false, true, 1, BigInteger.ZERO, 0); + Address acct = getNewExistentAccount(DEFAULT_BALANCE); + Address contract = createLockedAndLiveTRScontract(acct, false, true, 1, BigInteger.ZERO, 0); TRSuseContract trs = newTRSuseContract(acct); byte[] input = getDepositInput(contract, BigInteger.ONE); PrecompiledTransactionResult res = trs.execute(input, COST); @@ -517,16 +521,16 @@ public void testDepositWhileTRSisLive() { @Test public void testAccountIsValidPriorToDeposit() { - AionAddress acct = getNewExistentAccount(DEFAULT_BALANCE); - AionAddress contract = createTRScontract(acct, false, true, 1, BigInteger.ZERO, 0); + Address acct = getNewExistentAccount(DEFAULT_BALANCE); + Address contract = createTRScontract(acct, false, true, 1, BigInteger.ZERO, 0); TRSuseContract trs = newTRSuseContract(acct); assertFalse(accountIsValid(trs, contract, acct)); } @Test public void testAccountIsValidAfterDeposit() { - AionAddress acct = getNewExistentAccount(DEFAULT_BALANCE); - AionAddress contract = createTRScontract(acct, false, true, 1, BigInteger.ZERO, 0); + Address acct = getNewExistentAccount(DEFAULT_BALANCE); + Address contract = createTRScontract(acct, false, true, 1, BigInteger.ZERO, 0); TRSuseContract trs = newTRSuseContract(acct); byte[] input = getDepositInput(contract, BigInteger.ONE); trs.execute(input, COST); @@ -535,8 +539,8 @@ public void testAccountIsValidAfterDeposit() { @Test public void testAccountIsValidAfterMultipleDeposits() { - AionAddress acct = getNewExistentAccount(DEFAULT_BALANCE); - AionAddress contract = createTRScontract(acct, false, true, 1, BigInteger.ZERO, 0); + Address acct = getNewExistentAccount(DEFAULT_BALANCE); + Address contract = createTRScontract(acct, false, true, 1, BigInteger.ZERO, 0); TRSuseContract trs = newTRSuseContract(acct); byte[] input = getDepositInput(contract, BigInteger.ONE); trs.execute(input, COST); @@ -548,10 +552,10 @@ public void testAccountIsValidAfterMultipleDeposits() { @Test public void testMultipleAccountsValidAfterDeposits() { - AionAddress acct1 = getNewExistentAccount(DEFAULT_BALANCE); - AionAddress acct2 = getNewExistentAccount(DEFAULT_BALANCE); - AionAddress acct3 = getNewExistentAccount(DEFAULT_BALANCE); - AionAddress contract = createTRScontract(acct1, false, true, 1, BigInteger.ZERO, 0); + Address acct1 = getNewExistentAccount(DEFAULT_BALANCE); + Address acct2 = getNewExistentAccount(DEFAULT_BALANCE); + Address acct3 = getNewExistentAccount(DEFAULT_BALANCE); + Address contract = createTRScontract(acct1, false, true, 1, BigInteger.ZERO, 0); byte[] input = getDepositInput(contract, BigInteger.ONE); TRSuseContract trs1 = newTRSuseContract(acct1); @@ -575,8 +579,8 @@ public void testMultipleAccountsValidAfterDeposits() { @Test public void testAccountComingAndGoingSolo() { - AionAddress acct = getNewExistentAccount(DEFAULT_BALANCE); - AionAddress contract = createTRScontract(acct, false, true, 1, BigInteger.ZERO, 0); + Address acct = getNewExistentAccount(DEFAULT_BALANCE); + Address contract = createTRScontract(acct, false, true, 1, BigInteger.ZERO, 0); // Come. TRSuseContract trs = newTRSuseContract(acct); @@ -619,12 +623,12 @@ public void testAccountComingAndGoingSolo() { @Test public void testAccountComingAndGoingMultipleUsers() { - AionAddress owner = getNewExistentAccount(BigInteger.ONE); - AionAddress acct1 = getNewExistentAccount(DEFAULT_BALANCE); - AionAddress acct2 = getNewExistentAccount(DEFAULT_BALANCE); - AionAddress acct3 = getNewExistentAccount(DEFAULT_BALANCE); - AionAddress acct4 = getNewExistentAccount(DEFAULT_BALANCE); - AionAddress contract = createTRScontract(owner, false, true, 1, BigInteger.ZERO, 0); + Address owner = getNewExistentAccount(BigInteger.ONE); + Address acct1 = getNewExistentAccount(DEFAULT_BALANCE); + Address acct2 = getNewExistentAccount(DEFAULT_BALANCE); + Address acct3 = getNewExistentAccount(DEFAULT_BALANCE); + Address acct4 = getNewExistentAccount(DEFAULT_BALANCE); + Address contract = createTRScontract(owner, false, true, 1, BigInteger.ZERO, 0); TRSuseContract trs = newTRSuseContract(owner); // Come. We have: head-> acct4 <-> acct3 <-> acct2 <-> acct1 -> null @@ -715,11 +719,11 @@ public void testAccountComingAndGoingMultipleUsers() { @Test public void testWithdrawInputTooShort() { - AionAddress acct = getNewExistentAccount(DEFAULT_BALANCE); - AionAddress contract = createTRScontract(acct, false, true, 1, BigInteger.ZERO, 0); + Address acct = getNewExistentAccount(DEFAULT_BALANCE); + Address contract = createTRScontract(acct, false, true, 1, BigInteger.ZERO, 0); byte[] input = new byte[32]; input[0] = 0x1; - System.arraycopy(contract.toBytes(), 0, input, 1, AionAddress.SIZE - 1); + System.arraycopy(contract.toBytes(), 0, input, 1, Address.SIZE - 1); PrecompiledTransactionResult res = newTRSuseContract(acct).execute(input, COST); assertEquals(PrecompiledResultCode.FAILURE, res.getResultCode()); assertEquals(0, res.getEnergyRemaining()); @@ -727,11 +731,11 @@ public void testWithdrawInputTooShort() { @Test public void testWithdrawInputTooLong() { - AionAddress acct = getNewExistentAccount(DEFAULT_BALANCE); - AionAddress contract = createTRScontract(acct, false, true, 1, BigInteger.ZERO, 0); + Address acct = getNewExistentAccount(DEFAULT_BALANCE); + Address contract = createTRScontract(acct, false, true, 1, BigInteger.ZERO, 0); byte[] input = new byte[34]; input[0] = 0x1; - System.arraycopy(contract.toBytes(), 0, input, 1, AionAddress.SIZE); + System.arraycopy(contract.toBytes(), 0, input, 1, Address.SIZE); PrecompiledTransactionResult res = newTRSuseContract(acct).execute(input, COST); assertEquals(PrecompiledResultCode.FAILURE, res.getResultCode()); assertEquals(0, res.getEnergyRemaining()); @@ -739,11 +743,12 @@ public void testWithdrawInputTooLong() { @Test public void testWithdrawContractNotLockedOrLive() { - AionAddress acct = getNewExistentAccount(DEFAULT_BALANCE); - AionAddress contract = createTRScontract(acct, false, true, 1, BigInteger.ZERO, 0); + Address acct = getNewExistentAccount(DEFAULT_BALANCE); + Address contract = createTRScontract(acct, false, true, 1, BigInteger.ZERO, 0); byte[] input = getDepositInput(contract, DEFAULT_BALANCE); assertEquals( - PrecompiledResultCode.SUCCESS, newTRSuseContract(acct).execute(input, COST).getResultCode()); + PrecompiledResultCode.SUCCESS, + newTRSuseContract(acct).execute(input, COST).getResultCode()); input = getWithdrawInput(contract); PrecompiledTransactionResult res = newTRSuseContract(acct).execute(input, COST); @@ -754,16 +759,18 @@ public void testWithdrawContractNotLockedOrLive() { @Test public void testWithdrawContractLockedNotLive() { - AionAddress acct = getNewExistentAccount(DEFAULT_BALANCE); - AionAddress contract = createTRScontract(acct, false, true, 1, BigInteger.ZERO, 0); + Address acct = getNewExistentAccount(DEFAULT_BALANCE); + Address contract = createTRScontract(acct, false, true, 1, BigInteger.ZERO, 0); byte[] input = getDepositInput(contract, DEFAULT_BALANCE); assertEquals( - PrecompiledResultCode.SUCCESS, newTRSuseContract(acct).execute(input, COST).getResultCode()); + PrecompiledResultCode.SUCCESS, + newTRSuseContract(acct).execute(input, COST).getResultCode()); // Lock the contract. input = getLockInput(contract); assertEquals( - PrecompiledResultCode.SUCCESS, newTRSstateContract(acct).execute(input, COST).getResultCode()); + PrecompiledResultCode.SUCCESS, + newTRSstateContract(acct).execute(input, COST).getResultCode()); input = getWithdrawInput(contract); PrecompiledTransactionResult res = newTRSuseContract(acct).execute(input, COST); @@ -774,16 +781,16 @@ public void testWithdrawContractLockedNotLive() { @Test public void testLastWithdrawalPeriodNonExistentContract() { - AionAddress account = getNewExistentAccount(BigInteger.ONE); + Address account = getNewExistentAccount(BigInteger.ONE); assertEquals( -1, getAccountLastWithdrawalPeriod(newTRSuseContract(account), account, account)); } @Test public void testLastWithdrawalPeriodAccountNotInContract() { - AionAddress owner = getNewExistentAccount(BigInteger.ONE); - AionAddress stranger = getNewExistentAccount(BigInteger.ONE); - AionAddress contract = createTRScontract(owner, false, true, 1, BigInteger.ZERO, 0); + Address owner = getNewExistentAccount(BigInteger.ONE); + Address stranger = getNewExistentAccount(BigInteger.ONE); + Address contract = createTRScontract(owner, false, true, 1, BigInteger.ZERO, 0); assertEquals( -1, getAccountLastWithdrawalPeriod(newTRSuseContract(owner), contract, stranger)); @@ -792,13 +799,14 @@ public void testLastWithdrawalPeriodAccountNotInContract() { @Test public void testLastWithdrawalPeriodBeforeLive() { // Test before locking. - AionAddress owner = getNewExistentAccount(BigInteger.ONE); - AionAddress acc = getNewExistentAccount(BigInteger.ONE); - AionAddress contract = createTRScontract(owner, false, true, 1, BigInteger.ZERO, 0); + Address owner = getNewExistentAccount(BigInteger.ONE); + Address acc = getNewExistentAccount(BigInteger.ONE); + Address contract = createTRScontract(owner, false, true, 1, BigInteger.ZERO, 0); byte[] input = getDepositInput(contract, BigInteger.ONE); assertEquals( - PrecompiledResultCode.SUCCESS, newTRSuseContract(acc).execute(input, COST).getResultCode()); + PrecompiledResultCode.SUCCESS, + newTRSuseContract(acc).execute(input, COST).getResultCode()); assertEquals(0, getAccountLastWithdrawalPeriod(newTRSuseContract(owner), contract, acc)); // Test that locking changes nothing. @@ -811,13 +819,14 @@ public void testLastWithdrawalPeriodBeforeLive() { @Test public void testLastWithdrawalPeriodOnceLive() { - AionAddress owner = getNewExistentAccount(BigInteger.ONE); - AionAddress acc = getNewExistentAccount(BigInteger.ONE); - AionAddress contract = createTRScontract(owner, false, true, 1, BigInteger.ZERO, 0); + Address owner = getNewExistentAccount(BigInteger.ONE); + Address acc = getNewExistentAccount(BigInteger.ONE); + Address contract = createTRScontract(owner, false, true, 1, BigInteger.ZERO, 0); byte[] input = getDepositInput(contract, BigInteger.ONE); assertEquals( - PrecompiledResultCode.SUCCESS, newTRSuseContract(acc).execute(input, COST).getResultCode()); + PrecompiledResultCode.SUCCESS, + newTRSuseContract(acc).execute(input, COST).getResultCode()); input = getLockInput(contract); assertEquals( @@ -832,23 +841,26 @@ public void testLastWithdrawalPeriodOnceLive() { @Test public void testLastWithdrawalPeriodComingAndGoing() { - AionAddress owner = getNewExistentAccount(BigInteger.ONE); - AionAddress acc = getNewExistentAccount(BigInteger.ONE); - AionAddress contract = createTRScontract(owner, false, true, 1, BigInteger.ZERO, 0); + Address owner = getNewExistentAccount(BigInteger.ONE); + Address acc = getNewExistentAccount(BigInteger.ONE); + Address contract = createTRScontract(owner, false, true, 1, BigInteger.ZERO, 0); byte[] input = getDepositInput(contract, BigInteger.ONE); assertEquals( - PrecompiledResultCode.SUCCESS, newTRSuseContract(acc).execute(input, COST).getResultCode()); + PrecompiledResultCode.SUCCESS, + newTRSuseContract(acc).execute(input, COST).getResultCode()); assertEquals(0, getAccountLastWithdrawalPeriod(newTRSuseContract(owner), contract, acc)); input = getRefundInput(contract, acc, BigInteger.ONE); assertEquals( - PrecompiledResultCode.SUCCESS, newTRSuseContract(owner).execute(input, COST).getResultCode()); + PrecompiledResultCode.SUCCESS, + newTRSuseContract(owner).execute(input, COST).getResultCode()); assertEquals(-1, getAccountLastWithdrawalPeriod(newTRSuseContract(owner), contract, acc)); input = getDepositInput(contract, BigInteger.ONE); assertEquals( - PrecompiledResultCode.SUCCESS, newTRSuseContract(acc).execute(input, COST).getResultCode()); + PrecompiledResultCode.SUCCESS, + newTRSuseContract(acc).execute(input, COST).getResultCode()); assertEquals(0, getAccountLastWithdrawalPeriod(newTRSuseContract(owner), contract, acc)); } @@ -857,7 +869,7 @@ public void testWithdrawMultipleTimesSamePeriod() { int periods = DEFAULT_BALANCE.intValue(); repo.addBalance(AION, DEFAULT_BALANCE); BigInteger initBal = repo.getBalance(AION); - AionAddress contract = createTRScontract(AION, true, true, periods, BigInteger.ZERO, 0); + Address contract = createTRScontract(AION, true, true, periods, BigInteger.ZERO, 0); BigInteger expectedBalAfterDepo = initBal.subtract(DEFAULT_BALANCE); byte[] input = getDepositInput(contract, DEFAULT_BALANCE); @@ -899,7 +911,7 @@ public void testWithdrawNoBonusFunds() { int periods = 3; int numDepositors = 4; BigInteger total = deposits.multiply(BigInteger.valueOf(numDepositors)); - AionAddress contract = setupContract(numDepositors, deposits, bonus, periods, percent); + Address contract = setupContract(numDepositors, deposits, bonus, periods, percent); // We try to put the contract in a non-final period and withdraw. AbstractTRS trs = newTRSstateContract(AION); @@ -908,9 +920,9 @@ public void testWithdrawNoBonusFunds() { BigInteger expectedAmt = expectedAmtFirstWithdraw(trs, contract, deposits, total, bonus, percent, periods); - Set depositors = getAllDepositors(trs, contract); + Set
depositors = getAllDepositors(trs, contract); byte[] input = getWithdrawInput(contract); - for (AionAddress acc : depositors) { + for (Address acc : depositors) { assertEquals( PrecompiledResultCode.SUCCESS, newTRSuseContract(acc).execute(input, COST).getResultCode()); @@ -921,7 +933,7 @@ public void testWithdrawNoBonusFunds() { // origial balance back. mockBlockchain(timestamp + 3); assertEquals(periods, getContractCurrentPeriod(trs, contract)); - for (AionAddress acc : depositors) { + for (Address acc : depositors) { assertEquals( PrecompiledResultCode.SUCCESS, newTRSuseContract(acc).execute(input, COST).getResultCode()); @@ -937,7 +949,7 @@ public void testWithdrawSpecialOneOffOnFirstWithdraw() { int periods = 3; int depositors = 5; BigInteger total = deposits.multiply(BigInteger.valueOf(depositors)); - AionAddress contract = setupContract(depositors, deposits, bonus, periods, percent); + Address contract = setupContract(depositors, deposits, bonus, periods, percent); // Put the contract in a non-final period and withdraw. AbstractTRS trs = newTRSstateContract(AION); @@ -945,9 +957,9 @@ public void testWithdrawSpecialOneOffOnFirstWithdraw() { BigInteger expectedAmt = expectedAmtFirstWithdraw(trs, contract, deposits, total, bonus, percent, periods); - Set contributors = getAllDepositors(trs, contract); + Set
contributors = getAllDepositors(trs, contract); byte[] input = getWithdrawInput(contract); - for (AionAddress acc : contributors) { + for (Address acc : contributors) { assertEquals( PrecompiledResultCode.SUCCESS, newTRSuseContract(acc).execute(input, COST).getResultCode()); @@ -963,7 +975,7 @@ public void testWithdrawSpecialEventBeforePeriodOne() { int periods = 2; int depositors = 3; BigInteger total = deposits.multiply(BigInteger.valueOf(depositors)); - AionAddress contract = setupContract(depositors, deposits, bonus, periods, percent); + Address contract = setupContract(depositors, deposits, bonus, periods, percent); // Only genesis block exists so contract is live but the first period hasn't begun because // there is no block that has been made after the contract went live. All depositors will @@ -977,9 +989,9 @@ public void testWithdrawSpecialEventBeforePeriodOne() { new BigDecimal(bonus), percent); - Set contributors = getAllDepositors(trs, contract); + Set
contributors = getAllDepositors(trs, contract); byte[] input = getWithdrawInput(contract); - for (AionAddress acc : contributors) { + for (Address acc : contributors) { assertEquals( PrecompiledResultCode.SUCCESS, newTRSuseContract(acc).execute(input, COST).getResultCode()); @@ -987,7 +999,7 @@ public void testWithdrawSpecialEventBeforePeriodOne() { } // Let's try and withdraw again, now we should not be able to. - for (AionAddress acc : contributors) { + for (Address acc : contributors) { assertEquals( PrecompiledResultCode.FAILURE, newTRSuseContract(acc).execute(input, COST).getResultCode()); @@ -1003,7 +1015,7 @@ public void testWithdrawSomePeriodsBehind() { int periods = 7; int depositors = 5; BigInteger total = deposits.multiply(BigInteger.valueOf(depositors)); - AionAddress contract = setupContract(depositors, deposits, bonus, periods, percent); + Address contract = setupContract(depositors, deposits, bonus, periods, percent); // Put the contract in a non-final period greater than period 1 and withdraw. AbstractTRS trs = newTRSstateContract(AION); @@ -1011,9 +1023,9 @@ public void testWithdrawSomePeriodsBehind() { BigInteger expectedAmt = expectedAmtFirstWithdraw(trs, contract, deposits, total, bonus, percent, periods); - Set contributors = getAllDepositors(trs, contract); + Set
contributors = getAllDepositors(trs, contract); byte[] input = getWithdrawInput(contract); - for (AionAddress acc : contributors) { + for (Address acc : contributors) { assertEquals( PrecompiledResultCode.SUCCESS, newTRSuseContract(acc).execute(input, COST).getResultCode()); @@ -1029,7 +1041,7 @@ public void testWithdrawMultipleTimesInFinalPeriod() { int periods = 3; int depositors = 5; BigInteger total = deposits.multiply(BigInteger.valueOf(depositors)); - AionAddress contract = setupContract(depositors, deposits, bonus, periods, percent); + Address contract = setupContract(depositors, deposits, bonus, periods, percent); // Put the contract in a final period and withdraw. AbstractTRS trs = newTRSstateContract(AION); @@ -1038,9 +1050,9 @@ public void testWithdrawMultipleTimesInFinalPeriod() { BigInteger owings = grabOwings(new BigDecimal(deposits), new BigDecimal(total), new BigDecimal(bonus)); - Set contributors = getAllDepositors(trs, contract); + Set
contributors = getAllDepositors(trs, contract); byte[] input = getWithdrawInput(contract); - for (AionAddress acc : contributors) { + for (Address acc : contributors) { assertEquals( PrecompiledResultCode.SUCCESS, newTRSuseContract(acc).execute(input, COST).getResultCode()); @@ -1048,7 +1060,7 @@ public void testWithdrawMultipleTimesInFinalPeriod() { } // Try to withdraw again from the final period. - for (AionAddress acc : contributors) { + for (Address acc : contributors) { assertEquals( PrecompiledResultCode.FAILURE, newTRSuseContract(acc).execute(input, COST).getResultCode()); @@ -1064,7 +1076,7 @@ public void testWithdrawOncePerBlockTotalOwings() { int periods = 4; int depositors = 8; BigInteger total = deposits.multiply(BigInteger.valueOf(depositors)); - AionAddress contract = setupContract(depositors, deposits, bonus, periods, percent); + Address contract = setupContract(depositors, deposits, bonus, periods, percent); AbstractTRS trs = newTRSstateContract(AION); mockBlockchain(0); @@ -1076,8 +1088,8 @@ public void testWithdrawOncePerBlockTotalOwings() { while (!isDone) { isAccNotDone = false; - Set contributors = getAllDepositors(trs, contract); - for (AionAddress acc : contributors) { + Set
contributors = getAllDepositors(trs, contract); + for (Address acc : contributors) { if (newTRSuseContract(acc) .execute(input, COST) .getResultCode() @@ -1098,8 +1110,8 @@ public void testWithdrawOncePerBlockTotalOwings() { grabOwings(new BigDecimal(deposits), new BigDecimal(total), new BigDecimal(bonus)); BigInteger sum = BigInteger.ZERO; - Set contributors = getAllDepositors(trs, contract); - for (AionAddress acc : contributors) { + Set
contributors = getAllDepositors(trs, contract); + for (Address acc : contributors) { assertEquals(owings, repo.getBalance(acc)); sum = sum.add(owings); } @@ -1120,7 +1132,7 @@ public void testWithdrawLastPeriodOnlyTotalOwings() { int periods = 3; int depositors = 2; BigInteger total = deposits.multiply(BigInteger.valueOf(depositors)); - AionAddress contract = setupContract(depositors, deposits, bonus, periods, percent); + Address contract = setupContract(depositors, deposits, bonus, periods, percent); // We try to put the contract in the final period and withdraw. AbstractTRS trs = newTRSstateContract(AION); @@ -1132,9 +1144,9 @@ public void testWithdrawLastPeriodOnlyTotalOwings() { BigInteger accOwed = grabOwings(new BigDecimal(deposits), new BigDecimal(total), new BigDecimal(bonus)); - Set contributors = getAllDepositors(trs, contract); + Set
contributors = getAllDepositors(trs, contract); byte[] input = getWithdrawInput(contract); - for (AionAddress acc : contributors) { + for (Address acc : contributors) { assertEquals( PrecompiledResultCode.SUCCESS, newTRSuseContract(acc).execute(input, COST).getResultCode()); @@ -1150,7 +1162,7 @@ public void testWithdrawSomePeriodsTotalOwings() { int periods = 5; int depositors = 4; BigInteger total = deposits.multiply(BigInteger.valueOf(depositors)); - AionAddress contract = setupContract(depositors, deposits, bonus, periods, percent); + Address contract = setupContract(depositors, deposits, bonus, periods, percent); AbstractTRS trs = newTRSstateContract(AION); long timestamp = getContractTimestamp(trs, contract); @@ -1161,9 +1173,9 @@ public void testWithdrawSomePeriodsTotalOwings() { while (!isDone) { isAccNotDone = false; - Set contributors = getAllDepositors(trs, contract); + Set
contributors = getAllDepositors(trs, contract); byte[] input = getWithdrawInput(contract); - for (AionAddress acc : contributors) { + for (Address acc : contributors) { if (newTRSuseContract(acc) .execute(input, COST) .getResultCode() @@ -1184,8 +1196,8 @@ public void testWithdrawSomePeriodsTotalOwings() { grabOwings(new BigDecimal(deposits), new BigDecimal(total), new BigDecimal(bonus)); BigInteger sum = BigInteger.ZERO; - Set contributors = getAllDepositors(trs, contract); - for (AionAddress acc : contributors) { + Set
contributors = getAllDepositors(trs, contract); + for (Address acc : contributors) { assertEquals(owings, repo.getBalance(acc)); sum = sum.add(owings); } @@ -1203,20 +1215,23 @@ public void testWithdrawLargeWealthGap() { BigInteger bal1 = BigInteger.ONE; BigInteger bal2 = new BigInteger("968523984325"); BigInteger bal3 = new BigInteger("129387461289371"); - AionAddress acc1 = getNewExistentAccount(bal1); - AionAddress acc2 = getNewExistentAccount(bal2); - AionAddress acc3 = getNewExistentAccount(bal3); - AionAddress contract = createTRScontract(AION, true, true, 4, BigInteger.ZERO, 0); + Address acc1 = getNewExistentAccount(bal1); + Address acc2 = getNewExistentAccount(bal2); + Address acc3 = getNewExistentAccount(bal3); + Address contract = createTRScontract(AION, true, true, 4, BigInteger.ZERO, 0); byte[] input = getDepositInput(contract, bal1); assertEquals( - PrecompiledResultCode.SUCCESS, newTRSuseContract(acc1).execute(input, COST).getResultCode()); + PrecompiledResultCode.SUCCESS, + newTRSuseContract(acc1).execute(input, COST).getResultCode()); input = getDepositInput(contract, bal2); assertEquals( - PrecompiledResultCode.SUCCESS, newTRSuseContract(acc2).execute(input, COST).getResultCode()); + PrecompiledResultCode.SUCCESS, + newTRSuseContract(acc2).execute(input, COST).getResultCode()); input = getDepositInput(contract, bal3); assertEquals( - PrecompiledResultCode.SUCCESS, newTRSuseContract(acc3).execute(input, COST).getResultCode()); + PrecompiledResultCode.SUCCESS, + newTRSuseContract(acc3).execute(input, COST).getResultCode()); BigInteger bonus = new BigInteger("9238436745867623"); repo.addBalance(contract, bonus); lockAndStartContract(contract, AION); @@ -1229,8 +1244,8 @@ public void testWithdrawLargeWealthGap() { input = getWithdrawInput(contract); while (!isDone) { - Set contributors = getAllDepositors(trs, contract); - for (AionAddress acc : contributors) { + Set
contributors = getAllDepositors(trs, contract); + for (Address acc : contributors) { newTRSuseContract(acc).execute(input, COST); } @@ -1266,7 +1281,7 @@ public void testWithdrawOneDepositorTotalOwings() { int periods = 3; int depositors = 1; BigInteger total = deposits.multiply(BigInteger.valueOf(depositors)); - AionAddress contract = setupContract(depositors, deposits, bonus, periods, percent); + Address contract = setupContract(depositors, deposits, bonus, periods, percent); // We try to put the contract in a non-final period greater than period 1 and withdraw. AbstractTRS trs = newTRSstateContract(AION); @@ -1275,9 +1290,9 @@ public void testWithdrawOneDepositorTotalOwings() { BigInteger owings = grabOwings(new BigDecimal(deposits), new BigDecimal(total), new BigDecimal(bonus)); - Set contributors = getAllDepositors(trs, contract); + Set
contributors = getAllDepositors(trs, contract); byte[] input = getWithdrawInput(contract); - for (AionAddress acc : contributors) { + for (Address acc : contributors) { assertEquals( PrecompiledResultCode.SUCCESS, newTRSuseContract(acc).execute(input, COST).getResultCode()); @@ -1293,7 +1308,7 @@ public void testWithdrawSmallDepositsLargeBonus() { int periods = 4; int depositors = 8; BigInteger total = deposits.multiply(BigInteger.valueOf(depositors)); - AionAddress contract = setupContract(depositors, deposits, bonus, periods, percent); + Address contract = setupContract(depositors, deposits, bonus, periods, percent); // We try to put the contract in a non-final period and withdraw. AbstractTRS trs = newTRSstateContract(AION); @@ -1306,9 +1321,9 @@ public void testWithdrawSmallDepositsLargeBonus() { BigInteger amt = expectedAmtFirstWithdraw(trs, contract, deposits, total, bonus, percent, periods); - Set contributors = getAllDepositors(trs, contract); + Set
contributors = getAllDepositors(trs, contract); byte[] input = getWithdrawInput(contract); - for (AionAddress acc : contributors) { + for (Address acc : contributors) { assertEquals( PrecompiledResultCode.SUCCESS, newTRSuseContract(acc).execute(input, COST).getResultCode()); @@ -1318,7 +1333,7 @@ public void testWithdrawSmallDepositsLargeBonus() { // Now put contract in final period and withdraw. mockBlockchain(getContractTimestamp(trs, contract) + 5); assertEquals(BigInteger.valueOf(periods), getCurrentPeriod(trs, contract)); - for (AionAddress acc : contributors) { + for (Address acc : contributors) { assertEquals( PrecompiledResultCode.SUCCESS, newTRSuseContract(acc).execute(input, COST).getResultCode()); @@ -1334,7 +1349,7 @@ public void testWithdrawSpecialEventIsAllFunds() { int periods = 7; int depositors = 6; BigInteger total = deposits.multiply(BigInteger.valueOf(depositors)); - AionAddress contract = setupContract(depositors, deposits, bonus, periods, percent); + Address contract = setupContract(depositors, deposits, bonus, periods, percent); // No blocks, so only special withdrawal is available. Since special is 100% we claim our // total owings right here. @@ -1345,9 +1360,9 @@ public void testWithdrawSpecialEventIsAllFunds() { BigInteger owings = grabOwings(new BigDecimal(deposits), new BigDecimal(total), new BigDecimal(bonus)); - Set contributors = getAllDepositors(trs, contract); + Set
contributors = getAllDepositors(trs, contract); byte[] input = getWithdrawInput(contract); - for (AionAddress acc : contributors) { + for (Address acc : contributors) { assertEquals( PrecompiledResultCode.SUCCESS, newTRSuseContract(acc).execute(input, COST).getResultCode()); @@ -1356,7 +1371,7 @@ public void testWithdrawSpecialEventIsAllFunds() { // Now move into a non-final period and ensure no more withdrawals can be made. mockBlockchain(timestamp + 1); - for (AionAddress acc : contributors) { + for (Address acc : contributors) { assertEquals( PrecompiledResultCode.FAILURE, newTRSuseContract(acc).execute(input, COST).getResultCode()); @@ -1366,7 +1381,7 @@ public void testWithdrawSpecialEventIsAllFunds() { // Now move into a final period and ensure no more withdrawals can be made. mockBlockchain(timestamp + 7); assertEquals(BigInteger.valueOf(periods), getCurrentPeriod(trs, contract)); - for (AionAddress acc : contributors) { + for (Address acc : contributors) { assertEquals( PrecompiledResultCode.FAILURE, newTRSuseContract(acc).execute(input, COST).getResultCode()); @@ -1382,7 +1397,7 @@ public void testWithdrawSpecialEventVeryLarge() { int periods = 6; int depositors = 4; BigInteger total = deposits.multiply(BigInteger.valueOf(depositors)); - AionAddress contract = setupContract(depositors, deposits, bonus, periods, percent); + Address contract = setupContract(depositors, deposits, bonus, periods, percent); // No blocks, so only special withdrawal is available. The amount leftover from the special // is in the range (0,1) and so all subsequent withdrawal periods should withdraw zero until @@ -1397,9 +1412,9 @@ public void testWithdrawSpecialEventVeryLarge() { grabOwings(new BigDecimal(deposits), new BigDecimal(total), new BigDecimal(bonus)); assertTrue(amt.compareTo(owings) < 0); - Set contributors = getAllDepositors(trs, contract); + Set
contributors = getAllDepositors(trs, contract); byte[] input = getWithdrawInput(contract); - for (AionAddress acc : contributors) { + for (Address acc : contributors) { assertEquals( PrecompiledResultCode.SUCCESS, newTRSuseContract(acc).execute(input, COST).getResultCode()); @@ -1409,7 +1424,7 @@ public void testWithdrawSpecialEventVeryLarge() { // Now move into a non-final period and ensure all withdrawals fail (no positive amount to // claim). mockBlockchain(timestamp + 1); - for (AionAddress acc : contributors) { + for (Address acc : contributors) { assertEquals( PrecompiledResultCode.FAILURE, newTRSuseContract(acc).execute(input, COST).getResultCode()); @@ -1419,7 +1434,7 @@ public void testWithdrawSpecialEventVeryLarge() { // Now move into a final period and ensure we can make a withdrawal for our last coin. mockBlockchain(timestamp + 7); assertEquals(BigInteger.valueOf(periods), getCurrentPeriod(trs, contract)); - for (AionAddress acc : contributors) { + for (Address acc : contributors) { assertEquals( PrecompiledResultCode.SUCCESS, newTRSuseContract(acc).execute(input, COST).getResultCode()); @@ -1434,7 +1449,7 @@ public void testWithdrawMakeBonusDepositsAfterIsLive() { BigInteger bonus = BigInteger.ZERO; int periods = 2; int depositors = 3; - AionAddress contract = setupContract(depositors, deposits, bonus, periods, percent); + Address contract = setupContract(depositors, deposits, bonus, periods, percent); // Make a large bonus deposit while contract is live. repo.addBalance(contract, new BigInteger("876523876532534634")); @@ -1443,8 +1458,8 @@ public void testWithdrawMakeBonusDepositsAfterIsLive() { byte[] input = getWithdrawInput(contract); AbstractTRS trs = newTRSstateContract(AION); mockBlockchain(getContractTimestamp(trs, contract) + 3); - Set contributors = getAllDepositors(trs, contract); - for (AionAddress acc : contributors) { + Set
contributors = getAllDepositors(trs, contract); + for (Address acc : contributors) { assertEquals( PrecompiledResultCode.SUCCESS, newTRSuseContract(acc).execute(input, COST).getResultCode()); @@ -1460,7 +1475,7 @@ public void testWithdrawContractHasOnePeriod() { int periods = 1; int depositors = 3; BigInteger total = deposits.multiply(BigInteger.valueOf(depositors)); - AionAddress contract = setupContract(depositors, deposits, bonus, periods, percent); + Address contract = setupContract(depositors, deposits, bonus, periods, percent); BigInteger owings = grabOwings(new BigDecimal(deposits), new BigDecimal(total), new BigDecimal(bonus)); @@ -1469,8 +1484,8 @@ public void testWithdrawContractHasOnePeriod() { byte[] input = getWithdrawInput(contract); AbstractTRS trs = newTRSstateContract(AION); mockBlockchain(getContractTimestamp(trs, contract)); - Set contributors = getAllDepositors(trs, contract); - for (AionAddress acc : contributors) { + Set
contributors = getAllDepositors(trs, contract); + for (Address acc : contributors) { assertEquals( PrecompiledResultCode.SUCCESS, newTRSuseContract(acc).execute(input, COST).getResultCode()); @@ -1486,7 +1501,7 @@ public void testWithdrawSpecialPercentage18DecimalsPrecise() { int periods = 3; int depositors = 3; BigInteger total = deposits.multiply(BigInteger.valueOf(depositors)); - AionAddress contract = setupContract(depositors, deposits, bonus, periods, percent); + Address contract = setupContract(depositors, deposits, bonus, periods, percent); // Move into non-final period and withdraw. AbstractTRS trs = newTRSstateContract(AION); @@ -1507,7 +1522,7 @@ public void testWithdrawSpecialPercentage18DecimalsPrecise() { assertEquals(BigInteger.ONE, spec); assertEquals(amt, rawAmt.add(spec)); - Set contributors = getAllDepositors(trs, contract); + Set
contributors = getAllDepositors(trs, contract); byte[] input = getWithdrawInput(contract); boolean firstLook = true; @@ -1516,7 +1531,7 @@ public void testWithdrawSpecialPercentage18DecimalsPrecise() { while (!isDone) { isAccNotDone = false; - for (AionAddress acc : contributors) { + for (Address acc : contributors) { if (newTRSuseContract(acc) .execute(input, COST) .getResultCode() @@ -1536,7 +1551,7 @@ public void testWithdrawSpecialPercentage18DecimalsPrecise() { } } - for (AionAddress acc : contributors) { + for (Address acc : contributors) { assertEquals(owings, repo.getBalance(acc)); } } @@ -1546,11 +1561,11 @@ public void testWithdrawSpecialPercentage18DecimalsPrecise() { @Test public void testBulkWithdrawInputTooShort() { // Test maximum too-short size. - AionAddress acct = getNewExistentAccount(DEFAULT_BALANCE); - AionAddress contract = createTRScontract(acct, false, true, 1, BigInteger.ZERO, 0); + Address acct = getNewExistentAccount(DEFAULT_BALANCE); + Address contract = createTRScontract(acct, false, true, 1, BigInteger.ZERO, 0); byte[] input = new byte[32]; input[0] = 0x3; - System.arraycopy(contract.toBytes(), 0, input, 1, AionAddress.SIZE - 1); + System.arraycopy(contract.toBytes(), 0, input, 1, Address.SIZE - 1); PrecompiledTransactionResult res = newTRSuseContract(acct).execute(input, COST); assertEquals(PrecompiledResultCode.FAILURE, res.getResultCode()); assertEquals(0, res.getEnergyRemaining()); @@ -1564,11 +1579,11 @@ public void testBulkWithdrawInputTooShort() { @Test public void testBulkWithdrawInputTooLong() { - AionAddress acct = getNewExistentAccount(DEFAULT_BALANCE); - AionAddress contract = createTRScontract(acct, false, true, 1, BigInteger.ZERO, 0); + Address acct = getNewExistentAccount(DEFAULT_BALANCE); + Address contract = createTRScontract(acct, false, true, 1, BigInteger.ZERO, 0); byte[] input = new byte[34]; input[0] = 0x3; - System.arraycopy(contract.toBytes(), 0, input, 1, AionAddress.SIZE); + System.arraycopy(contract.toBytes(), 0, input, 1, Address.SIZE); PrecompiledTransactionResult res = newTRSuseContract(acct).execute(input, COST); assertEquals(PrecompiledResultCode.FAILURE, res.getResultCode()); assertEquals(0, res.getEnergyRemaining()); @@ -1581,28 +1596,28 @@ public void testBulkWithdrawCallerNotOwner() { BigInteger bonus = new BigInteger("326543"); int periods = 3; int depositors = 6; - AionAddress contract = setupContract(depositors, deposits, bonus, periods, percent); + Address contract = setupContract(depositors, deposits, bonus, periods, percent); // Try to do a bulk-withdraw calling as every depositor in the contract (owner is AION). byte[] input = getBulkWithdrawInput(contract); AbstractTRS trs = newTRSstateContract(AION); - Set contributors = getAllDepositors(trs, contract); - for (AionAddress acc : contributors) { + Set
contributors = getAllDepositors(trs, contract); + for (Address acc : contributors) { assertEquals( PrecompiledResultCode.FAILURE, newTRSuseContract(acc).execute(input, COST).getResultCode()); } // Verify no one received any funds. - for (AionAddress acc : contributors) { + for (Address acc : contributors) { assertEquals(BigInteger.ZERO, repo.getBalance(acc)); } } @Test public void testBulkWithdrawContractNotLockedNotLive() { - AionAddress acct = getNewExistentAccount(DEFAULT_BALANCE); - AionAddress contract = createTRScontract(acct, false, true, 1, BigInteger.ZERO, 0); + Address acct = getNewExistentAccount(DEFAULT_BALANCE); + Address contract = createTRScontract(acct, false, true, 1, BigInteger.ZERO, 0); // Try first with no one in the contract. Caller is owner. byte[] input = getBulkWithdrawInput(contract); @@ -1613,7 +1628,8 @@ public void testBulkWithdrawContractNotLockedNotLive() { // Now deposit some and try again. input = getDepositInput(contract, DEFAULT_BALANCE); assertEquals( - PrecompiledResultCode.SUCCESS, newTRSuseContract(acct).execute(input, COST).getResultCode()); + PrecompiledResultCode.SUCCESS, + newTRSuseContract(acct).execute(input, COST).getResultCode()); input = getBulkWithdrawInput(contract); assertEquals( PrecompiledResultCode.FAILURE, @@ -1622,16 +1638,18 @@ public void testBulkWithdrawContractNotLockedNotLive() { @Test public void testBulkWithdrawContractLockedNotLive() { - AionAddress acct = getNewExistentAccount(DEFAULT_BALANCE); - AionAddress contract = createTRScontract(acct, false, true, 1, BigInteger.ZERO, 0); + Address acct = getNewExistentAccount(DEFAULT_BALANCE); + Address contract = createTRScontract(acct, false, true, 1, BigInteger.ZERO, 0); // Deposit some funds and lock. byte[] input = getDepositInput(contract, DEFAULT_BALANCE); assertEquals( - PrecompiledResultCode.SUCCESS, newTRSuseContract(acct).execute(input, COST).getResultCode()); + PrecompiledResultCode.SUCCESS, + newTRSuseContract(acct).execute(input, COST).getResultCode()); input = getLockInput(contract); assertEquals( - PrecompiledResultCode.SUCCESS, newTRSstateContract(acct).execute(input, COST).getResultCode()); + PrecompiledResultCode.SUCCESS, + newTRSstateContract(acct).execute(input, COST).getResultCode()); // Try to withdraw. input = getBulkWithdrawInput(contract); @@ -1648,18 +1666,19 @@ public void testBulkWithdrawOneDepositor() { BigInteger bonus = new BigInteger("346"); int periods = 4; int depositors = 1; - AionAddress contract = setupContract(depositors, deposits, bonus, periods, percent); + Address contract = setupContract(depositors, deposits, bonus, periods, percent); // Verify depositor has no account balance. AbstractTRS trs = newTRSstateContract(AION); - AionAddress depositor = getAllDepositors(trs, contract).iterator().next(); + Address depositor = getAllDepositors(trs, contract).iterator().next(); assertEquals(BigInteger.ZERO, repo.getBalance(depositor)); mockBlockchain(getContractTimestamp(trs, contract) + 1); // Do a bulk-withdraw from the contract. byte[] input = getBulkWithdrawInput(contract); assertEquals( - PrecompiledResultCode.SUCCESS, newTRSuseContract(AION).execute(input, COST).getResultCode()); + PrecompiledResultCode.SUCCESS, + newTRSuseContract(AION).execute(input, COST).getResultCode()); BigInteger amt = expectedAmtFirstWithdraw( trs, contract, deposits, deposits, bonus, percent, periods); @@ -1673,7 +1692,7 @@ public void testBulkWithdrawMultipleDepositors() { BigInteger bonus = new BigInteger("18946896534"); int periods = 3; int depositors = 6; - AionAddress contract = setupContract(depositors, deposits, bonus, periods, percent); + Address contract = setupContract(depositors, deposits, bonus, periods, percent); AbstractTRS trs = newTRSstateContract(AION); mockBlockchain(getContractTimestamp(trs, contract) + 1); @@ -1684,20 +1703,22 @@ public void testBulkWithdrawMultipleDepositors() { // Do a bulk-withdraw on the contract. byte[] input = getBulkWithdrawInput(contract); assertEquals( - PrecompiledResultCode.SUCCESS, newTRSuseContract(AION).execute(input, COST).getResultCode()); + PrecompiledResultCode.SUCCESS, + newTRSuseContract(AION).execute(input, COST).getResultCode()); - Set contributors = getAllDepositors(trs, contract); - for (AionAddress acc : contributors) { + Set
contributors = getAllDepositors(trs, contract); + for (Address acc : contributors) { assertEquals(amt, repo.getBalance(acc)); } // Move into final period and withdraw the rest. mockBlockchain(getContractTimestamp(trs, contract) + 4); assertEquals( - PrecompiledResultCode.SUCCESS, newTRSuseContract(AION).execute(input, COST).getResultCode()); + PrecompiledResultCode.SUCCESS, + newTRSuseContract(AION).execute(input, COST).getResultCode()); BigInteger owings = grabOwings(new BigDecimal(deposits), new BigDecimal(total), new BigDecimal(bonus)); - for (AionAddress acc : contributors) { + for (Address acc : contributors) { assertEquals(owings, repo.getBalance(acc)); } } @@ -1709,7 +1730,7 @@ public void testBulkWithdrawSomeDepositorsHaveWithdrawnSomeNotThisPeriod() { BigInteger bonus = new BigInteger("345"); int periods = 3; int depositors = 5; - AionAddress contract = setupContract(depositors, deposits, bonus, periods, percent); + Address contract = setupContract(depositors, deposits, bonus, periods, percent); AbstractTRS trs = newTRSstateContract(AION); mockBlockchain(getContractTimestamp(trs, contract) + 1); @@ -1720,8 +1741,8 @@ public void testBulkWithdrawSomeDepositorsHaveWithdrawnSomeNotThisPeriod() { // Have half of the depositors withdraw. byte[] input = getWithdrawInput(contract); boolean withdraw = true; - Set contributors = getAllDepositors(trs, contract); - for (AionAddress acc : contributors) { + Set
contributors = getAllDepositors(trs, contract); + for (Address acc : contributors) { if (withdraw) { assertEquals( PrecompiledResultCode.SUCCESS, @@ -1736,8 +1757,9 @@ public void testBulkWithdrawSomeDepositorsHaveWithdrawnSomeNotThisPeriod() { // Do a bulk-withdraw on the contract. Check all accounts have amt now and no one has more. input = getBulkWithdrawInput(contract); assertEquals( - PrecompiledResultCode.SUCCESS, newTRSuseContract(AION).execute(input, COST).getResultCode()); - for (AionAddress acc : contributors) { + PrecompiledResultCode.SUCCESS, + newTRSuseContract(AION).execute(input, COST).getResultCode()); + for (Address acc : contributors) { assertEquals(amt, repo.getBalance(acc)); } } @@ -1749,7 +1771,7 @@ public void testBulkWithdrawSpecialEventBeforeLiveBlockArrives() { BigInteger bonus = new BigInteger("3").pow(13); int periods = 4; int depositors = 3; - AionAddress contract = setupContract(depositors, deposits, bonus, periods, percent); + Address contract = setupContract(depositors, deposits, bonus, periods, percent); // We are not yet live. AbstractTRS trs = newTRSstateContract(AION); @@ -1765,11 +1787,12 @@ public void testBulkWithdrawSpecialEventBeforeLiveBlockArrives() { new BigDecimal(bonus), percent); - Set contributors = getAllDepositors(trs, contract); + Set
contributors = getAllDepositors(trs, contract); byte[] input = getBulkWithdrawInput(contract); assertEquals( - PrecompiledResultCode.SUCCESS, newTRSuseContract(AION).execute(input, COST).getResultCode()); - for (AionAddress acc : contributors) { + PrecompiledResultCode.SUCCESS, + newTRSuseContract(AION).execute(input, COST).getResultCode()); + for (Address acc : contributors) { assertEquals(spec, repo.getBalance(acc)); } } @@ -1781,7 +1804,7 @@ public void testBulkWithdrawAtFinalPeriod() { BigInteger bonus = new BigInteger("3274436"); int periods = 4; int depositors = 12; - AionAddress contract = setupContract(depositors, deposits, bonus, periods, percent); + Address contract = setupContract(depositors, deposits, bonus, periods, percent); // Move contract into its final period. AbstractTRS trs = newTRSstateContract(AION); @@ -1796,11 +1819,12 @@ public void testBulkWithdrawAtFinalPeriod() { assertTrue( (owings.multiply(BigInteger.valueOf(depositors))).compareTo(total.add(bonus)) <= 0); - Set contributors = getAllDepositors(trs, contract); + Set
contributors = getAllDepositors(trs, contract); byte[] input = getBulkWithdrawInput(contract); assertEquals( - PrecompiledResultCode.SUCCESS, newTRSuseContract(AION).execute(input, COST).getResultCode()); - for (AionAddress acc : contributors) { + PrecompiledResultCode.SUCCESS, + newTRSuseContract(AION).execute(input, COST).getResultCode()); + for (Address acc : contributors) { assertEquals(owings, repo.getBalance(acc)); } } @@ -1812,7 +1836,7 @@ public void testBulkWithdrawMultipleTimesSpecialPeriod() { BigInteger bonus = new BigInteger("3").pow(13); int periods = 4; int depositors = 3; - AionAddress contract = setupContract(depositors, deposits, bonus, periods, percent); + Address contract = setupContract(depositors, deposits, bonus, periods, percent); // We are not yet live. AbstractTRS trs = newTRSstateContract(AION); @@ -1828,19 +1852,21 @@ public void testBulkWithdrawMultipleTimesSpecialPeriod() { new BigDecimal(bonus), percent); - Set contributors = getAllDepositors(trs, contract); + Set
contributors = getAllDepositors(trs, contract); byte[] input = getBulkWithdrawInput(contract); assertEquals( - PrecompiledResultCode.SUCCESS, newTRSuseContract(AION).execute(input, COST).getResultCode()); - for (AionAddress acc : contributors) { + PrecompiledResultCode.SUCCESS, + newTRSuseContract(AION).execute(input, COST).getResultCode()); + for (Address acc : contributors) { assertEquals(spec, repo.getBalance(acc)); } // Attempt to do another bulk withdraw in this same period; account balances should not // change. assertEquals( - PrecompiledResultCode.SUCCESS, newTRSuseContract(AION).execute(input, COST).getResultCode()); - for (AionAddress acc : contributors) { + PrecompiledResultCode.SUCCESS, + newTRSuseContract(AION).execute(input, COST).getResultCode()); + for (Address acc : contributors) { assertEquals(spec, repo.getBalance(acc)); } } @@ -1852,7 +1878,7 @@ public void testBulkWithdrawMultipleTimesNonFinalPeriod() { BigInteger bonus = new BigInteger("8347634"); int periods = 6; int depositors = 8; - AionAddress contract = setupContract(depositors, deposits, bonus, periods, percent); + Address contract = setupContract(depositors, deposits, bonus, periods, percent); // Move contract into a non-final period. AbstractTRS trs = newTRSstateContract(AION); @@ -1863,19 +1889,21 @@ public void testBulkWithdrawMultipleTimesNonFinalPeriod() { BigInteger amt = expectedAmtFirstWithdraw(trs, contract, deposits, total, bonus, percent, periods); - Set contributors = getAllDepositors(trs, contract); + Set
contributors = getAllDepositors(trs, contract); byte[] input = getBulkWithdrawInput(contract); assertEquals( - PrecompiledResultCode.SUCCESS, newTRSuseContract(AION).execute(input, COST).getResultCode()); - for (AionAddress acc : contributors) { + PrecompiledResultCode.SUCCESS, + newTRSuseContract(AION).execute(input, COST).getResultCode()); + for (Address acc : contributors) { assertEquals(amt, repo.getBalance(acc)); } // Attempt to do another bulk withdraw in this same period; account balances should not // change. assertEquals( - PrecompiledResultCode.SUCCESS, newTRSuseContract(AION).execute(input, COST).getResultCode()); - for (AionAddress acc : contributors) { + PrecompiledResultCode.SUCCESS, + newTRSuseContract(AION).execute(input, COST).getResultCode()); + for (Address acc : contributors) { assertEquals(amt, repo.getBalance(acc)); } } @@ -1887,7 +1915,7 @@ public void testBulkWithdrawMultipleTimesFinalPeriod() { BigInteger bonus = new BigInteger("650000"); int periods = 2; int depositors = 11; - AionAddress contract = setupContract(depositors, deposits, bonus, periods, percent); + Address contract = setupContract(depositors, deposits, bonus, periods, percent); // Move contract into a non-final period. AbstractTRS trs = newTRSstateContract(AION); @@ -1898,19 +1926,21 @@ public void testBulkWithdrawMultipleTimesFinalPeriod() { BigInteger owings = grabOwings(new BigDecimal(deposits), new BigDecimal(total), new BigDecimal(bonus)); - Set contributors = getAllDepositors(trs, contract); + Set
contributors = getAllDepositors(trs, contract); byte[] input = getBulkWithdrawInput(contract); assertEquals( - PrecompiledResultCode.SUCCESS, newTRSuseContract(AION).execute(input, COST).getResultCode()); - for (AionAddress acc : contributors) { + PrecompiledResultCode.SUCCESS, + newTRSuseContract(AION).execute(input, COST).getResultCode()); + for (Address acc : contributors) { assertEquals(owings, repo.getBalance(acc)); } // Attempt to do another bulk withdraw in this same period; account balances should not // change. assertEquals( - PrecompiledResultCode.SUCCESS, newTRSuseContract(AION).execute(input, COST).getResultCode()); - for (AionAddress acc : contributors) { + PrecompiledResultCode.SUCCESS, + newTRSuseContract(AION).execute(input, COST).getResultCode()); + for (Address acc : contributors) { assertEquals(owings, repo.getBalance(acc)); } } @@ -1920,7 +1950,7 @@ public void testBulkWithdrawMultipleTimesFinalPeriod() { @Test public void testRefundInputTooShort() { // Test maximum too-short size. - AionAddress acct = getNewExistentAccount(DEFAULT_BALANCE); + Address acct = getNewExistentAccount(DEFAULT_BALANCE); byte[] input = new byte[192]; PrecompiledTransactionResult res = newTRSuseContract(acct).execute(input, COST); assertEquals(PrecompiledResultCode.FAILURE, res.getResultCode()); @@ -1935,7 +1965,7 @@ public void testRefundInputTooShort() { @Test public void testRefundInputTooLarge() { - AionAddress acct = getNewExistentAccount(DEFAULT_BALANCE); + Address acct = getNewExistentAccount(DEFAULT_BALANCE); byte[] input = new byte[194]; PrecompiledTransactionResult res = newTRSuseContract(acct).execute(input, COST); assertEquals(PrecompiledResultCode.FAILURE, res.getResultCode()); @@ -1945,8 +1975,8 @@ public void testRefundInputTooLarge() { @Test public void testRefundBadTRScontract() { // Test TRS address that looks like regular account address. - AionAddress acct = getNewExistentAccount(DEFAULT_BALANCE); - AionAddress contract = getNewExistentAccount(DEFAULT_BALANCE); + Address acct = getNewExistentAccount(DEFAULT_BALANCE); + Address contract = getNewExistentAccount(DEFAULT_BALANCE); byte[] input = getRefundInput(contract, acct, BigInteger.ZERO); PrecompiledTransactionResult res = newTRSuseContract(acct).execute(input, COST); assertEquals(PrecompiledResultCode.FAILURE, res.getResultCode()); @@ -1965,9 +1995,9 @@ public void testRefundBadTRScontract() { @Test public void testRefundCallerIsNotOwner() { - AionAddress acct = getNewExistentAccount(DEFAULT_BALANCE); - AionAddress acct2 = getNewExistentAccount(DEFAULT_BALANCE); - AionAddress contract = createTRScontract(acct, false, true, 1, BigInteger.ZERO, 0); + Address acct = getNewExistentAccount(DEFAULT_BALANCE); + Address acct2 = getNewExistentAccount(DEFAULT_BALANCE); + Address contract = createTRScontract(acct, false, true, 1, BigInteger.ZERO, 0); // acct2 deposits so that it does have a balance to refund from. byte[] input = getDepositInput(contract, BigInteger.ONE); @@ -1984,9 +2014,9 @@ public void testRefundCallerIsNotOwner() { @Test public void testRefundAccountNotInContract() { - AionAddress acct = getNewExistentAccount(DEFAULT_BALANCE); - AionAddress acct2 = getNewExistentAccount(DEFAULT_BALANCE); - AionAddress contract = createTRScontract(acct, false, true, 1, BigInteger.ZERO, 0); + Address acct = getNewExistentAccount(DEFAULT_BALANCE); + Address acct2 = getNewExistentAccount(DEFAULT_BALANCE); + Address contract = createTRScontract(acct, false, true, 1, BigInteger.ZERO, 0); // acct2 has never deposited and is not a valid account in the contract yet. byte[] input = getRefundInput(contract, acct2, BigInteger.ONE); @@ -1996,14 +2026,16 @@ public void testRefundAccountNotInContract() { assertEquals(0, res.getEnergyRemaining()); // Have others deposit but not acct2 and try again ... should be same result. - AionAddress acct3 = getNewExistentAccount(DEFAULT_BALANCE); - AionAddress acct4 = getNewExistentAccount(DEFAULT_BALANCE); + Address acct3 = getNewExistentAccount(DEFAULT_BALANCE); + Address acct4 = getNewExistentAccount(DEFAULT_BALANCE); input = getDepositInput(contract, DEFAULT_BALANCE); assertEquals( - PrecompiledResultCode.SUCCESS, newTRSuseContract(acct3).execute(input, COST).getResultCode()); + PrecompiledResultCode.SUCCESS, + newTRSuseContract(acct3).execute(input, COST).getResultCode()); assertEquals( - PrecompiledResultCode.SUCCESS, newTRSuseContract(acct4).execute(input, COST).getResultCode()); + PrecompiledResultCode.SUCCESS, + newTRSuseContract(acct4).execute(input, COST).getResultCode()); input = getRefundInput(contract, acct2, BigInteger.ONE); res = newTRSuseContract(acct2).execute(input, COST); @@ -2013,19 +2045,21 @@ public void testRefundAccountNotInContract() { @Test public void testRefundContractIsLocked() { - AionAddress acct = getNewExistentAccount(BigInteger.ONE); - AionAddress acct2 = getNewExistentAccount(DEFAULT_BALANCE); - AionAddress contract = createTRScontract(acct, false, true, 1, BigInteger.ZERO, 0); + Address acct = getNewExistentAccount(BigInteger.ONE); + Address acct2 = getNewExistentAccount(DEFAULT_BALANCE); + Address contract = createTRScontract(acct, false, true, 1, BigInteger.ZERO, 0); // Have acct2 deposit some balance. byte[] input = getDepositInput(contract, DEFAULT_BALANCE); assertEquals( - PrecompiledResultCode.SUCCESS, newTRSuseContract(acct2).execute(input, COST).getResultCode()); + PrecompiledResultCode.SUCCESS, + newTRSuseContract(acct2).execute(input, COST).getResultCode()); // Now lock the contract. input = getLockInput(contract); assertEquals( - PrecompiledResultCode.SUCCESS, newTRSstateContract(acct).execute(input, COST).getResultCode()); + PrecompiledResultCode.SUCCESS, + newTRSstateContract(acct).execute(input, COST).getResultCode()); // Now have contract owner try to refund acct2. input = getRefundInput(contract, acct2, BigInteger.ONE); @@ -2036,22 +2070,25 @@ public void testRefundContractIsLocked() { @Test public void testRefundContractIsLive() { - AionAddress acct = getNewExistentAccount(BigInteger.ONE); - AionAddress acct2 = getNewExistentAccount(DEFAULT_BALANCE); - AionAddress contract = createTRScontract(acct, false, true, 1, BigInteger.ZERO, 0); + Address acct = getNewExistentAccount(BigInteger.ONE); + Address acct2 = getNewExistentAccount(DEFAULT_BALANCE); + Address contract = createTRScontract(acct, false, true, 1, BigInteger.ZERO, 0); // Have acct2 deposit some balance. byte[] input = getDepositInput(contract, DEFAULT_BALANCE); assertEquals( - PrecompiledResultCode.SUCCESS, newTRSuseContract(acct2).execute(input, COST).getResultCode()); + PrecompiledResultCode.SUCCESS, + newTRSuseContract(acct2).execute(input, COST).getResultCode()); // Now lock the contract and make it live. input = getLockInput(contract); assertEquals( - PrecompiledResultCode.SUCCESS, newTRSstateContract(acct).execute(input, COST).getResultCode()); + PrecompiledResultCode.SUCCESS, + newTRSstateContract(acct).execute(input, COST).getResultCode()); input = getStartInput(contract); assertEquals( - PrecompiledResultCode.SUCCESS, newTRSstateContract(acct).execute(input, COST).getResultCode()); + PrecompiledResultCode.SUCCESS, + newTRSstateContract(acct).execute(input, COST).getResultCode()); // Now have contract owner try to refund acct2. input = getRefundInput(contract, acct2, BigInteger.ONE); @@ -2062,14 +2099,15 @@ public void testRefundContractIsLive() { @Test public void testRefundAccountBalanceInsufficient() { - AionAddress acct = getNewExistentAccount(BigInteger.ONE); - AionAddress acct2 = getNewExistentAccount(DEFAULT_BALANCE); - AionAddress contract = createTRScontract(acct, false, true, 1, BigInteger.ZERO, 0); + Address acct = getNewExistentAccount(BigInteger.ONE); + Address acct2 = getNewExistentAccount(DEFAULT_BALANCE); + Address contract = createTRScontract(acct, false, true, 1, BigInteger.ZERO, 0); // Have acct2 deposit some balance. byte[] input = getDepositInput(contract, DEFAULT_BALANCE); assertEquals( - PrecompiledResultCode.SUCCESS, newTRSuseContract(acct2).execute(input, COST).getResultCode()); + PrecompiledResultCode.SUCCESS, + newTRSuseContract(acct2).execute(input, COST).getResultCode()); // Now have contract owner try to refund acct2 for more than acct2 has deposited. input = getRefundInput(contract, acct2, DEFAULT_BALANCE.add(BigInteger.ONE)); @@ -2080,9 +2118,9 @@ public void testRefundAccountBalanceInsufficient() { @Test public void testRefundAccountFullBalance() { - AionAddress acct = getNewExistentAccount(BigInteger.ONE); - AionAddress acct2 = getNewExistentAccount(DEFAULT_BALANCE); - AionAddress contract = createTRScontract(acct, false, true, 1, BigInteger.ZERO, 0); + Address acct = getNewExistentAccount(BigInteger.ONE); + Address acct2 = getNewExistentAccount(DEFAULT_BALANCE); + Address contract = createTRScontract(acct, false, true, 1, BigInteger.ZERO, 0); assertEquals(DEFAULT_BALANCE, repo.getBalance(acct2)); @@ -2112,8 +2150,8 @@ public void testRefundAccountFullBalance() { public void testRefundAccountFullBalance2() { // Same as above test but we test here a balance that spans multiple storage rows. BigInteger max = getMaxOneTimeDeposit(); - AionAddress acct = getNewExistentAccount(max); - AionAddress contract = createTRScontract(acct, false, true, 1, BigInteger.ZERO, 0); + Address acct = getNewExistentAccount(max); + Address contract = createTRScontract(acct, false, true, 1, BigInteger.ZERO, 0); assertEquals(max, repo.getBalance(acct)); @@ -2140,8 +2178,8 @@ public void testRefundAccountFullBalance2() { @Test public void testRefundAccountBalanceLeftover() { BigInteger max = getMaxOneTimeDeposit(); - AionAddress acct = getNewExistentAccount(max); - AionAddress contract = createTRScontract(acct, false, true, 1, BigInteger.ZERO, 0); + Address acct = getNewExistentAccount(max); + Address contract = createTRScontract(acct, false, true, 1, BigInteger.ZERO, 0); assertEquals(max, repo.getBalance(acct)); @@ -2172,10 +2210,10 @@ public void testRefundTotalBalanceMultipleAccounts() { BigInteger funds1 = new BigInteger("439378943235235"); BigInteger funds2 = new BigInteger("298598364"); BigInteger funds3 = new BigInteger("9832958020263806345437400898000"); - AionAddress acct1 = getNewExistentAccount(funds1); - AionAddress acct2 = getNewExistentAccount(funds2); - AionAddress acct3 = getNewExistentAccount(funds3); - AionAddress contract = createTRScontract(acct1, false, true, 1, BigInteger.ZERO, 0); + Address acct1 = getNewExistentAccount(funds1); + Address acct2 = getNewExistentAccount(funds2); + Address acct3 = getNewExistentAccount(funds3); + Address contract = createTRScontract(acct1, false, true, 1, BigInteger.ZERO, 0); // Make some deposits. byte[] input = getDepositInput(contract, funds1); @@ -2201,13 +2239,16 @@ public void testRefundTotalBalanceMultipleAccounts() { BigInteger diff2 = new BigInteger("196254756"); input = getRefundInput(contract, acct1, funds1.subtract(diff1)); assertEquals( - PrecompiledResultCode.SUCCESS, newTRSuseContract(acct1).execute(input, COST).getResultCode()); + PrecompiledResultCode.SUCCESS, + newTRSuseContract(acct1).execute(input, COST).getResultCode()); input = getRefundInput(contract, acct2, funds2.subtract(diff2)); assertEquals( - PrecompiledResultCode.SUCCESS, newTRSuseContract(acct1).execute(input, COST).getResultCode()); + PrecompiledResultCode.SUCCESS, + newTRSuseContract(acct1).execute(input, COST).getResultCode()); input = getRefundInput(contract, acct3, funds3); assertEquals( - PrecompiledResultCode.SUCCESS, newTRSuseContract(acct1).execute(input, COST).getResultCode()); + PrecompiledResultCode.SUCCESS, + newTRSuseContract(acct1).execute(input, COST).getResultCode()); assertEquals(diff1, getDepositBalance(trs, contract, acct1)); assertEquals(diff2, getDepositBalance(trs, contract, acct2)); @@ -2221,9 +2262,9 @@ public void testRefundTotalBalanceMultipleAccounts() { @Test public void testRefundInvalidAccount() { // We make an account invalid by depositing and then fully refunding it. - AionAddress acct = getNewExistentAccount(BigInteger.ONE); - AionAddress acct2 = getNewExistentAccount(DEFAULT_BALANCE); - AionAddress contract = createTRScontract(acct, false, true, 1, BigInteger.ZERO, 0); + Address acct = getNewExistentAccount(BigInteger.ONE); + Address acct2 = getNewExistentAccount(DEFAULT_BALANCE); + Address contract = createTRScontract(acct, false, true, 1, BigInteger.ZERO, 0); assertEquals(DEFAULT_BALANCE, repo.getBalance(acct2)); @@ -2255,9 +2296,9 @@ public void testRefundInvalidAccount() { @Test public void testRefundZeroForNonExistentAccount() { - AionAddress acct = getNewExistentAccount(DEFAULT_BALANCE); - AionAddress acct2 = getNewExistentAccount(DEFAULT_BALANCE); - AionAddress contract = createTRScontract(acct, false, true, 1, BigInteger.ZERO, 0); + Address acct = getNewExistentAccount(DEFAULT_BALANCE); + Address acct2 = getNewExistentAccount(DEFAULT_BALANCE); + Address contract = createTRScontract(acct, false, true, 1, BigInteger.ZERO, 0); byte[] input = getRefundInput(contract, acct2, BigInteger.ZERO); TRSuseContract trs = newTRSuseContract(acct); PrecompiledTransactionResult res = trs.execute(input, COST); @@ -2267,16 +2308,18 @@ public void testRefundZeroForNonExistentAccount() { @Test public void testRefundZeroForInvalidAccount() { - AionAddress acct = getNewExistentAccount(DEFAULT_BALANCE); - AionAddress acct2 = getNewExistentAccount(DEFAULT_BALANCE); - AionAddress contract = createTRScontract(acct, false, true, 1, BigInteger.ZERO, 0); + Address acct = getNewExistentAccount(DEFAULT_BALANCE); + Address acct2 = getNewExistentAccount(DEFAULT_BALANCE); + Address contract = createTRScontract(acct, false, true, 1, BigInteger.ZERO, 0); byte[] input = getDepositInput(contract, DEFAULT_BALANCE); assertEquals( - PrecompiledResultCode.SUCCESS, newTRSuseContract(acct2).execute(input, COST).getResultCode()); + PrecompiledResultCode.SUCCESS, + newTRSuseContract(acct2).execute(input, COST).getResultCode()); input = getRefundInput(contract, acct2, DEFAULT_BALANCE); assertEquals( - PrecompiledResultCode.SUCCESS, newTRSuseContract(acct).execute(input, COST).getResultCode()); + PrecompiledResultCode.SUCCESS, + newTRSuseContract(acct).execute(input, COST).getResultCode()); // Acct2 is now marked invalid. input = getRefundInput(contract, acct2, BigInteger.ZERO); @@ -2287,18 +2330,20 @@ public void testRefundZeroForInvalidAccount() { @Test public void testRefundZeroForValidAccount() { - AionAddress acct = getNewExistentAccount(DEFAULT_BALANCE); - AionAddress acct2 = getNewExistentAccount(DEFAULT_BALANCE); - AionAddress contract = createTRScontract(acct, false, true, 1, BigInteger.ZERO, 0); + Address acct = getNewExistentAccount(DEFAULT_BALANCE); + Address acct2 = getNewExistentAccount(DEFAULT_BALANCE); + Address contract = createTRScontract(acct, false, true, 1, BigInteger.ZERO, 0); byte[] input = getDepositInput(contract, DEFAULT_BALANCE); assertEquals( - PrecompiledResultCode.SUCCESS, newTRSuseContract(acct2).execute(input, COST).getResultCode()); + PrecompiledResultCode.SUCCESS, + newTRSuseContract(acct2).execute(input, COST).getResultCode()); // Now try to refund nothing, acct2 exists in the contract. input = getRefundInput(contract, acct2, BigInteger.ZERO); assertEquals( - PrecompiledResultCode.SUCCESS, newTRSuseContract(acct).execute(input, COST).getResultCode()); + PrecompiledResultCode.SUCCESS, + newTRSuseContract(acct).execute(input, COST).getResultCode()); // Verify nothing actually changed. TRSuseContract trs = newTRSuseContract(acct); @@ -2309,13 +2354,14 @@ public void testRefundZeroForValidAccount() { @Test public void testRefundSuccessNrgLeft() { - AionAddress acct = getNewExistentAccount(DEFAULT_BALANCE); - AionAddress acct2 = getNewExistentAccount(DEFAULT_BALANCE); - AionAddress contract = createTRScontract(acct, false, true, 1, BigInteger.ZERO, 0); + Address acct = getNewExistentAccount(DEFAULT_BALANCE); + Address acct2 = getNewExistentAccount(DEFAULT_BALANCE); + Address contract = createTRScontract(acct, false, true, 1, BigInteger.ZERO, 0); byte[] input = getDepositInput(contract, DEFAULT_BALANCE); assertEquals( - PrecompiledResultCode.SUCCESS, newTRSuseContract(acct2).execute(input, COST).getResultCode()); + PrecompiledResultCode.SUCCESS, + newTRSuseContract(acct2).execute(input, COST).getResultCode()); long diff = 47835; input = getRefundInput(contract, acct2, BigInteger.ZERO); @@ -2330,8 +2376,8 @@ public void testRefundSuccessNrgLeft() { @Test public void testDepositForInputTooLong() { - AionAddress acct = getNewExistentAccount(BigInteger.ONE); - AionAddress contract = createTRScontract(acct, false, false, 1, BigInteger.ZERO, 0); + Address acct = getNewExistentAccount(BigInteger.ONE); + Address contract = createTRScontract(acct, false, false, 1, BigInteger.ZERO, 0); byte[] input = getDepositForInput(contract, acct, BigInteger.ONE); byte[] longInput = new byte[input.length + 1]; @@ -2344,8 +2390,8 @@ public void testDepositForInputTooLong() { @Test public void testDepositForInputTooShort() { - AionAddress acct = getNewExistentAccount(BigInteger.ONE); - AionAddress contract = createTRScontract(acct, false, false, 1, BigInteger.ZERO, 0); + Address acct = getNewExistentAccount(BigInteger.ONE); + Address contract = createTRScontract(acct, false, false, 1, BigInteger.ZERO, 0); byte[] input = getDepositForInput(contract, acct, BigInteger.ONE); byte[] shortInput = new byte[input.length - 1]; @@ -2358,8 +2404,8 @@ public void testDepositForInputTooShort() { @Test public void testDepositForContractIsLocked() { - AionAddress acct = getNewExistentAccount(BigInteger.ONE); - AionAddress contract = createAndLockTRScontract(acct, false, false, 1, BigInteger.ZERO, 0); + Address acct = getNewExistentAccount(BigInteger.ONE); + Address contract = createAndLockTRScontract(acct, false, false, 1, BigInteger.ZERO, 0); byte[] input = getDepositForInput(contract, acct, BigInteger.ONE); PrecompiledTransactionResult res = newTRSuseContract(acct).execute(input, COST); @@ -2369,8 +2415,8 @@ public void testDepositForContractIsLocked() { @Test public void testDepositForContractIsLive() { - AionAddress acct = getNewExistentAccount(BigInteger.ONE); - AionAddress contract = + Address acct = getNewExistentAccount(BigInteger.ONE); + Address contract = createLockedAndLiveTRScontract(acct, false, false, 1, BigInteger.ZERO, 0); byte[] input = getDepositForInput(contract, acct, BigInteger.ONE); @@ -2381,9 +2427,9 @@ public void testDepositForContractIsLive() { @Test public void testDepositForCallerIsNotOwner() { - AionAddress acct = getNewExistentAccount(BigInteger.ONE); - AionAddress whoami = getNewExistentAccount(DEFAULT_BALANCE); - AionAddress contract = createTRScontract(acct, false, false, 1, BigInteger.ZERO, 0); + Address acct = getNewExistentAccount(BigInteger.ONE); + Address whoami = getNewExistentAccount(DEFAULT_BALANCE); + Address contract = createTRScontract(acct, false, false, 1, BigInteger.ZERO, 0); byte[] input = getDepositForInput(contract, whoami, DEFAULT_BALANCE); PrecompiledTransactionResult res = newTRSuseContract(whoami).execute(input, COST); @@ -2394,9 +2440,9 @@ public void testDepositForCallerIsNotOwner() { @Test public void testDepositForCallerHasInsufficientFunds() { // Owner does not have adequate funds but the recipient of the deposit-for does. - AionAddress owner = getNewExistentAccount(BigInteger.ONE); - AionAddress other = getNewExistentAccount(DEFAULT_BALANCE); - AionAddress contract = createTRScontract(owner, false, false, 1, BigInteger.ZERO, 0); + Address owner = getNewExistentAccount(BigInteger.ONE); + Address other = getNewExistentAccount(DEFAULT_BALANCE); + Address contract = createTRScontract(owner, false, false, 1, BigInteger.ZERO, 0); byte[] input = getDepositForInput(contract, other, DEFAULT_BALANCE); PrecompiledTransactionResult res = newTRSuseContract(owner).execute(input, COST); @@ -2405,11 +2451,11 @@ public void testDepositForCallerHasInsufficientFunds() { } @Test - public void testDepositForNonAionAddressAsDepositor() { + public void testDepositForNonAddressAsDepositor() { // The deposit-for recipient is another trs contract... - AionAddress owner = getNewExistentAccount(BigInteger.ONE); - AionAddress other = createTRScontract(owner, false, false, 1, BigInteger.ZERO, 0); - AionAddress contract = createTRScontract(owner, false, false, 1, BigInteger.ZERO, 0); + Address owner = getNewExistentAccount(BigInteger.ONE); + Address other = createTRScontract(owner, false, false, 1, BigInteger.ZERO, 0); + Address contract = createTRScontract(owner, false, false, 1, BigInteger.ZERO, 0); byte[] input = getDepositForInput(contract, other, BigInteger.ONE); PrecompiledTransactionResult res = newTRSuseContract(owner).execute(input, COST); @@ -2419,11 +2465,11 @@ public void testDepositForNonAionAddressAsDepositor() { @Test public void testDepositForContractAddressIsInvalid() { - AionAddress owner = getNewExistentAccount(BigInteger.ONE); - AionAddress other = getNewExistentAccount(DEFAULT_BALANCE); + Address owner = getNewExistentAccount(BigInteger.ONE); + Address other = getNewExistentAccount(DEFAULT_BALANCE); byte[] addr = Arrays.copyOf(other.toBytes(), other.toBytes().length); addr[0] = (byte) 0xC0; - AionAddress contract = new AionAddress(addr); + Address contract = new AionAddress(addr); byte[] input = getDepositForInput(contract, other, BigInteger.ONE); PrecompiledTransactionResult res = newTRSuseContract(owner).execute(input, COST); @@ -2433,9 +2479,9 @@ public void testDepositForContractAddressIsInvalid() { @Test public void testDepositForZeroAmount() { - AionAddress owner = getNewExistentAccount(BigInteger.ONE); - AionAddress other = getNewExistentAccount(DEFAULT_BALANCE); - AionAddress contract = createTRScontract(owner, false, false, 1, BigInteger.ZERO, 0); + Address owner = getNewExistentAccount(BigInteger.ONE); + Address other = getNewExistentAccount(DEFAULT_BALANCE); + Address contract = createTRScontract(owner, false, false, 1, BigInteger.ZERO, 0); // Verify other has zero balance after this (also owner just to make sure) AbstractTRS trs = newTRSuseContract(owner); @@ -2451,9 +2497,9 @@ public void testDepositForZeroAmount() { @Test public void testDepositForOneAccount() { // other does not need any funds. - AionAddress owner = getNewExistentAccount(DEFAULT_BALANCE); - AionAddress other = getNewExistentAccount(BigInteger.ZERO); - AionAddress contract = createTRScontract(owner, false, false, 1, BigInteger.ZERO, 0); + Address owner = getNewExistentAccount(DEFAULT_BALANCE); + Address other = getNewExistentAccount(BigInteger.ZERO); + Address contract = createTRScontract(owner, false, false, 1, BigInteger.ZERO, 0); // Verify other has zero balance after this (also owner just to make sure) AbstractTRS trs = newTRSuseContract(owner); @@ -2469,11 +2515,11 @@ public void testDepositForOneAccount() { @Test public void testDepositForMultipleAccounts() { BigInteger balance = new BigInteger("832523626"); - AionAddress owner = getNewExistentAccount(balance.multiply(BigInteger.valueOf(4))); - AionAddress other1 = getNewExistentAccount(BigInteger.ZERO); - AionAddress other2 = getNewExistentAccount(BigInteger.ZERO); - AionAddress other3 = getNewExistentAccount(BigInteger.ZERO); - AionAddress contract = createTRScontract(owner, false, false, 1, BigInteger.ZERO, 0); + Address owner = getNewExistentAccount(balance.multiply(BigInteger.valueOf(4))); + Address other1 = getNewExistentAccount(BigInteger.ZERO); + Address other2 = getNewExistentAccount(BigInteger.ZERO); + Address other3 = getNewExistentAccount(BigInteger.ZERO); + Address contract = createTRScontract(owner, false, false, 1, BigInteger.ZERO, 0); AbstractTRS trs = newTRSuseContract(owner); byte[] input = getDepositForInput(contract, other1, balance); @@ -2494,12 +2540,12 @@ public void testDepositForMultipleAccounts() { public void testDepositForSameAccountMultipleTimes() { BigInteger balance = new BigInteger("8293652893346342674375477457554345"); int times = 61; - AionAddress owner = + Address owner = getNewExistentAccount( (balance.multiply(BigInteger.TWO)).multiply(BigInteger.valueOf(times))); - AionAddress other1 = getNewExistentAccount(BigInteger.ZERO); - AionAddress other2 = getNewExistentAccount(BigInteger.ZERO); - AionAddress contract = createTRScontract(owner, false, false, 1, BigInteger.ZERO, 0); + Address other1 = getNewExistentAccount(BigInteger.ZERO); + Address other2 = getNewExistentAccount(BigInteger.ZERO); + Address contract = createTRScontract(owner, false, false, 1, BigInteger.ZERO, 0); AbstractTRS trs = newTRSuseContract(owner); byte[] input = getDepositForInput(contract, other1, balance); @@ -2524,8 +2570,8 @@ public void testDepositForSameAccountMultipleTimes() { @Test public void testDepositForOneself() { // No reason why an owner can't use depositFor to deposit on his/her own behalf. - AionAddress owner = getNewExistentAccount(DEFAULT_BALANCE); - AionAddress contract = createTRScontract(owner, false, false, 1, BigInteger.ZERO, 0); + Address owner = getNewExistentAccount(DEFAULT_BALANCE); + Address contract = createTRScontract(owner, false, false, 1, BigInteger.ZERO, 0); // Verify other has zero balance after this (also owner just to make sure) AbstractTRS trs = newTRSuseContract(owner); @@ -2541,8 +2587,8 @@ public void testDepositForOneself() { @Test public void testAddExtraInputTooShort() { - AionAddress acct = getNewExistentAccount(DEFAULT_BALANCE); - AionAddress contract = createTRScontract(acct, false, true, 1, BigInteger.ZERO, 0); + Address acct = getNewExistentAccount(DEFAULT_BALANCE); + Address contract = createTRScontract(acct, false, true, 1, BigInteger.ZERO, 0); byte[] input = getAddExtraInput(contract, DEFAULT_BALANCE); byte[] shortInput = Arrays.copyOf(input, input.length - 1); assertEquals( @@ -2552,8 +2598,8 @@ public void testAddExtraInputTooShort() { @Test public void testAddExtraInputTooLong() { - AionAddress acct = getNewExistentAccount(DEFAULT_BALANCE); - AionAddress contract = createTRScontract(acct, false, true, 1, BigInteger.ZERO, 0); + Address acct = getNewExistentAccount(DEFAULT_BALANCE); + Address contract = createTRScontract(acct, false, true, 1, BigInteger.ZERO, 0); byte[] input = getAddExtraInput(contract, DEFAULT_BALANCE); byte[] longInput = new byte[input.length + 1]; System.arraycopy(input, 0, longInput, 0, input.length); @@ -2564,7 +2610,7 @@ public void testAddExtraInputTooLong() { @Test public void testAddExtraContractNonExistent() { - AionAddress acct = getNewExistentAccount(DEFAULT_BALANCE); + Address acct = getNewExistentAccount(DEFAULT_BALANCE); byte[] input = getAddExtraInput(acct, DEFAULT_BALANCE); assertEquals( PrecompiledResultCode.FAILURE, @@ -2573,8 +2619,8 @@ public void testAddExtraContractNonExistent() { @Test public void testAddExtraCallerIsNotOwner() { - AionAddress acct = getNewExistentAccount(DEFAULT_BALANCE); - AionAddress contract = createTRScontract(AION, false, true, 1, BigInteger.ZERO, 0); + Address acct = getNewExistentAccount(DEFAULT_BALANCE); + Address contract = createTRScontract(AION, false, true, 1, BigInteger.ZERO, 0); byte[] input = getAddExtraInput(contract, DEFAULT_BALANCE); assertEquals( PrecompiledResultCode.FAILURE, @@ -2583,8 +2629,8 @@ public void testAddExtraCallerIsNotOwner() { @Test public void testAddExtraCallHasInsufficientFunds() { - AionAddress acct = getNewExistentAccount(DEFAULT_BALANCE); - AionAddress contract = createTRScontract(acct, false, true, 1, BigInteger.ZERO, 0); + Address acct = getNewExistentAccount(DEFAULT_BALANCE); + Address contract = createTRScontract(acct, false, true, 1, BigInteger.ZERO, 0); byte[] input = getAddExtraInput(contract, DEFAULT_BALANCE.add(BigInteger.ONE)); assertEquals( PrecompiledResultCode.INSUFFICIENT_BALANCE, @@ -2593,11 +2639,12 @@ public void testAddExtraCallHasInsufficientFunds() { @Test public void testAddExtraFundsOpen() { - AionAddress acct = getNewExistentAccount(DEFAULT_BALANCE); - AionAddress contract = createTRScontract(acct, false, true, 1, BigInteger.ZERO, 0); + Address acct = getNewExistentAccount(DEFAULT_BALANCE); + Address contract = createTRScontract(acct, false, true, 1, BigInteger.ZERO, 0); byte[] input = getOpenFundsInput(contract); assertEquals( - PrecompiledResultCode.SUCCESS, newTRSstateContract(acct).execute(input, COST).getResultCode()); + PrecompiledResultCode.SUCCESS, + newTRSstateContract(acct).execute(input, COST).getResultCode()); assertTrue(getAreContractFundsOpen(newTRSstateContract(acct), contract)); input = getAddExtraInput(contract, DEFAULT_BALANCE); @@ -2608,8 +2655,8 @@ public void testAddExtraFundsOpen() { @Test public void testExtraFundsNewContract() { - AionAddress acct = getNewExistentAccount(DEFAULT_BALANCE); - AionAddress contract = createTRScontract(acct, false, true, 1, BigInteger.ZERO, 0); + Address acct = getNewExistentAccount(DEFAULT_BALANCE); + Address contract = createTRScontract(acct, false, true, 1, BigInteger.ZERO, 0); AbstractTRS trs = newTRSuseContract(acct); assertEquals(BigInteger.ZERO, getExtraFunds(trs, contract)); @@ -2617,8 +2664,8 @@ public void testExtraFundsNewContract() { @Test public void testAddZeroExtraFunds() { - AionAddress acct = getNewExistentAccount(DEFAULT_BALANCE); - AionAddress contract = createTRScontract(acct, false, true, 1, BigInteger.ZERO, 0); + Address acct = getNewExistentAccount(DEFAULT_BALANCE); + Address contract = createTRScontract(acct, false, true, 1, BigInteger.ZERO, 0); AbstractTRS trs = newTRSuseContract(acct); byte[] input = getAddExtraInput(contract, BigInteger.ZERO); @@ -2630,8 +2677,8 @@ public void testAddZeroExtraFunds() { @Test public void testAddExtraFundsUnlocked() { BigInteger amt = new BigInteger("32985623956237896532753265332"); - AionAddress acct = getNewExistentAccount(amt); - AionAddress contract = createTRScontract(acct, false, true, 1, BigInteger.ZERO, 0); + Address acct = getNewExistentAccount(amt); + Address contract = createTRScontract(acct, false, true, 1, BigInteger.ZERO, 0); AbstractTRS trs = newTRSuseContract(acct); byte[] input = getAddExtraInput(contract, amt); @@ -2643,8 +2690,8 @@ public void testAddExtraFundsUnlocked() { @Test public void testAddExtraFundsLocked() { BigInteger amt = new BigInteger("32985623956237896532753265332").add(BigInteger.ONE); - AionAddress acct = getNewExistentAccount(amt); - AionAddress contract = createAndLockTRScontract(acct, false, true, 1, BigInteger.ZERO, 0); + Address acct = getNewExistentAccount(amt); + Address contract = createAndLockTRScontract(acct, false, true, 1, BigInteger.ZERO, 0); AbstractTRS trs = newTRSuseContract(acct); byte[] input = getAddExtraInput(contract, amt.subtract(BigInteger.ONE)); @@ -2656,8 +2703,8 @@ public void testAddExtraFundsLocked() { @Test public void testAddExtraFundsLive() { BigInteger amt = new BigInteger("32985623956237896532753265332").add(BigInteger.ONE); - AionAddress acct = getNewExistentAccount(amt); - AionAddress contract = createLockedAndLiveTRScontract(acct, false, true, 1, BigInteger.ZERO, 0); + Address acct = getNewExistentAccount(amt); + Address contract = createLockedAndLiveTRScontract(acct, false, true, 1, BigInteger.ZERO, 0); AbstractTRS trs = newTRSuseContract(acct); byte[] input = getAddExtraInput(contract, amt.subtract(BigInteger.ONE)); @@ -2670,8 +2717,8 @@ public void testAddExtraFundsLive() { public void testAddMaxExtraFunds() { int times = 23; BigInteger amt = getMaxOneTimeDeposit().multiply(BigInteger.valueOf(times)); - AionAddress acct = getNewExistentAccount(amt); - AionAddress contract = createTRScontract(acct, false, true, 1, BigInteger.ZERO, 0); + Address acct = getNewExistentAccount(amt); + Address contract = createTRScontract(acct, false, true, 1, BigInteger.ZERO, 0); AbstractTRS trs = newTRSuseContract(acct); byte[] input = getAddExtraMaxInput(contract); @@ -2690,7 +2737,7 @@ public void testAddExtraDuringSpecialWithdrawPeriod() { BigInteger bonus = new BigInteger("237856238756235"); BigInteger extra = new BigInteger("32865237523"); BigDecimal percent = new BigDecimal("41.12221"); - AionAddress contract = setupContract(numDepositors, deposits, bonus, periods, percent); + Address contract = setupContract(numDepositors, deposits, bonus, periods, percent); // In the special-only period, extra funds are unable to be withdrawn. AbstractTRS trs = newTRSuseContract(AION); @@ -2699,9 +2746,9 @@ public void testAddExtraDuringSpecialWithdrawPeriod() { assertEquals(PrecompiledResultCode.SUCCESS, trs.execute(input, COST).getResultCode()); mockBlockchain(0); - Set contributors = getAllDepositors(trs, contract); + Set
contributors = getAllDepositors(trs, contract); BigInteger total = deposits.multiply(BigInteger.valueOf(numDepositors)); - for (AionAddress acc : contributors) { + for (Address acc : contributors) { BigInteger amt = expectedAmtFirstWithdraw( trs, contract, deposits, total, bonus, percent, periods); @@ -2721,7 +2768,7 @@ public void testAddExtraNonFinalPeriod() { BigInteger bonus = new BigInteger("23454234"); BigInteger extra = new BigInteger("43895634825643872563478934"); BigDecimal percent = new BigDecimal("1"); - AionAddress contract = setupContract(numDepositors, deposits, bonus, periods, percent); + Address contract = setupContract(numDepositors, deposits, bonus, periods, percent); AbstractTRS trs = newTRSuseContract(AION); repo.addBalance(AION, extra); @@ -2742,7 +2789,7 @@ public void testAddExtraFinalPeriod() { BigInteger bonus = new BigInteger("5454534"); BigInteger extra = new BigInteger("34238462353567234"); BigDecimal percent = new BigDecimal("16"); - AionAddress contract = setupContract(numDepositors, deposits, bonus, periods, percent); + Address contract = setupContract(numDepositors, deposits, bonus, periods, percent); AbstractTRS trs = newTRSuseContract(AION); mockBlockchain(getContractTimestamp(trs, contract) + 3); @@ -2763,7 +2810,7 @@ public void testAddExtraWithdrawMultipleTimesSpecialPeriod() { BigInteger bonus = new BigInteger("436436343434"); BigInteger extra = new BigInteger("457457457454856986786534"); BigDecimal percent = new BigDecimal("11.123"); - AionAddress contract = setupContract(numDepositors, deposits, bonus, periods, percent); + Address contract = setupContract(numDepositors, deposits, bonus, periods, percent); AbstractTRS trs = newTRSuseContract(AION); repo.addBalance(AION, extra); @@ -2772,12 +2819,12 @@ public void testAddExtraWithdrawMultipleTimesSpecialPeriod() { mockBlockchain(0); // We have half the contributors withdraw now. No extras are collected. - Set contributors = getAllDepositors(trs, contract); + Set
contributors = getAllDepositors(trs, contract); BigInteger total = deposits.multiply(BigInteger.valueOf(numDepositors)); input = getWithdrawInput(contract); boolean withdraw = true; - for (AionAddress acc : contributors) { + for (Address acc : contributors) { BigInteger amt = expectedAmtFirstWithdraw( trs, contract, deposits, total, bonus, percent, periods); @@ -2801,7 +2848,7 @@ public void testAddExtraWithdrawMultipleTimesSpecialPeriod() { input = getWithdrawInput(contract); withdraw = true; - for (AionAddress acc : contributors) { + for (Address acc : contributors) { BigInteger amt = expectedAmtFirstWithdraw( trs, contract, deposits, total, bonus, percent, periods); @@ -2828,7 +2875,7 @@ public void testAddExtraWithdrawMultipleTimesSameNonFinalPeriod() { BigInteger bonus = new BigInteger("325436346546345634634634346"); BigInteger extra = new BigInteger("1000"); BigDecimal percent = new BigDecimal("18.888"); - AionAddress contract = setupContract(numDepositors, deposits, bonus, periods, percent); + Address contract = setupContract(numDepositors, deposits, bonus, periods, percent); // We add some extra funds and half the accounts make a withdrawal, half don't. AbstractTRS trs = newTRSuseContract(AION); @@ -2839,7 +2886,7 @@ public void testAddExtraWithdrawMultipleTimesSameNonFinalPeriod() { int currPeriod = getContractCurrentPeriod(trs, contract); assertTrue(currPeriod < periods); - Set contributors = getAllDepositors(trs, contract); + Set
contributors = getAllDepositors(trs, contract); BigInteger total = deposits.multiply(BigInteger.valueOf(numDepositors)); BigDecimal fraction = BigDecimal.ONE.divide( @@ -2848,7 +2895,7 @@ public void testAddExtraWithdrawMultipleTimesSameNonFinalPeriod() { BigInteger prevAmt = null; input = getWithdrawInput(contract); boolean withdraw = true; - for (AionAddress acc : contributors) { + for (Address acc : contributors) { BigInteger extraShare = getExtraShare(trs, contract, acc, fraction, currPeriod); BigInteger amt = expectedAmtFirstWithdraw( @@ -2875,7 +2922,7 @@ public void testAddExtraWithdrawMultipleTimesSameNonFinalPeriod() { expectedAmtFirstWithdraw(trs, contract, deposits, total, bonus, percent, periods); input = getWithdrawInput(contract); withdraw = true; - for (AionAddress acc : contributors) { + for (Address acc : contributors) { BigInteger extraShare = getExtraShare(trs, contract, acc, fraction, currPeriod); if (withdraw) { // These have already withdrawn. @@ -2895,7 +2942,7 @@ public void testAddExtraWithdrawMultipleTimesSameNonFinalPeriod() { // Verify that after this everyone has collected the same amount. BigInteger bal = null; - for (AionAddress acc : contributors) { + for (Address acc : contributors) { if (bal == null) { bal = repo.getBalance(acc); } else { @@ -2912,7 +2959,7 @@ public void testAddExtraWithdrawMultipleTimesFinalPeriod() { BigInteger bonus = new BigInteger("877654634456"); BigInteger extra = new BigInteger("2213322345"); BigDecimal percent = new BigDecimal("27"); - AionAddress contract = setupContract(numDepositors, deposits, bonus, periods, percent); + Address contract = setupContract(numDepositors, deposits, bonus, periods, percent); // Add the extra funds and then withdraw everything. AbstractTRS trs = newTRSuseContract(AION); @@ -2923,7 +2970,7 @@ public void testAddExtraWithdrawMultipleTimesFinalPeriod() { int currPeriod = getContractCurrentPeriod(trs, contract); assertEquals(currPeriod, periods); - Set contributors = getAllDepositors(trs, contract); + Set
contributors = getAllDepositors(trs, contract); BigDecimal fraction = BigDecimal.ONE.divide( BigDecimal.valueOf(numDepositors), 18, RoundingMode.HALF_DOWN); @@ -2931,7 +2978,7 @@ public void testAddExtraWithdrawMultipleTimesFinalPeriod() { BigInteger owings = grabOwings(new BigDecimal(deposits), new BigDecimal(total), new BigDecimal(bonus)); BigInteger prevAmt = null; - for (AionAddress acc : contributors) { + for (Address acc : contributors) { BigInteger share = getExtraShare(trs, contract, acc, fraction, currPeriod); input = getWithdrawInput(contract); assertEquals( @@ -2945,7 +2992,7 @@ public void testAddExtraWithdrawMultipleTimesFinalPeriod() { repo.addBalance(AION, extra); input = getAddExtraInput(contract, extra); assertEquals(PrecompiledResultCode.SUCCESS, trs.execute(input, COST).getResultCode()); - for (AionAddress acc : contributors) { + for (Address acc : contributors) { BigInteger share = getExtraShare(trs, contract, acc, fraction, currPeriod); input = getWithdrawInput(contract); assertEquals( @@ -2955,7 +3002,7 @@ public void testAddExtraWithdrawMultipleTimesFinalPeriod() { } // Attempt to withdraw again, everyone should fail now because all extras have been claimed. - for (AionAddress acc : contributors) { + for (Address acc : contributors) { BigInteger share = getExtraShare(trs, contract, acc, fraction, currPeriod); input = getWithdrawInput(contract); assertEquals( @@ -2972,14 +3019,14 @@ public void testAddExtraMultipleTimesMultipleWithdrawsOverContractLifetime() { BigInteger bonus = new BigInteger("82364545474572"); BigInteger extra = new BigInteger("563233323552"); BigDecimal percent = new BigDecimal("12.05"); - AionAddress contract = setupContract(numDepositors, deposits, bonus, periods, percent); + Address contract = setupContract(numDepositors, deposits, bonus, periods, percent); // Each loop we deposit some extra balance and have everyone withdraw. This loop has users // withdrawing multiple times per each period until done. AbstractTRS trs = newTRSuseContract(AION); long timestamp = getContractTimestamp(trs, contract); mockBlockchain(0); - Set contributors = getAllDepositors(trs, contract); + Set
contributors = getAllDepositors(trs, contract); byte[] input; BigInteger extraSum = BigInteger.ZERO; int attemptsPerPeriod = 3; @@ -2987,11 +3034,12 @@ public void testAddExtraMultipleTimesMultipleWithdrawsOverContractLifetime() { if (i % (attemptsPerPeriod - 1) == 0) { repo.addBalance(AION, extra); input = getAddExtraInput(contract, extra); - assertEquals(PrecompiledResultCode.SUCCESS, trs.execute(input, COST).getResultCode()); + assertEquals( + PrecompiledResultCode.SUCCESS, trs.execute(input, COST).getResultCode()); extraSum = extraSum.add(extra); } - for (AionAddress acc : contributors) { + for (Address acc : contributors) { input = getWithdrawInput(contract); newTRSuseContract(acc).execute(input, COST); } @@ -3010,7 +3058,7 @@ public void testAddExtraMultipleTimesMultipleWithdrawsOverContractLifetime() { BigInteger bonusShare = fraction.multiply(new BigDecimal(bonus)).toBigInteger(); BigInteger extraShare = fraction.multiply(new BigDecimal(extraSum)).toBigInteger(); BigInteger expectedAmt = deposits.add(bonusShare).add(extraShare); - for (AionAddress acc : contributors) { + for (Address acc : contributors) { assertEquals(expectedAmt, repo.getBalance(acc)); } @@ -3025,8 +3073,8 @@ public void testAddExtraMultipleTimesMultipleWithdrawsOverContractLifetime() { @Test public void testBulkDepositForInputTooShort() { - AionAddress acct = getNewExistentAccount(BigInteger.ONE); - AionAddress contract = createTRScontract(acct, false, false, 1, BigInteger.ZERO, 0); + Address acct = getNewExistentAccount(BigInteger.ONE); + Address contract = createTRScontract(acct, false, false, 1, BigInteger.ZERO, 0); int numBeneficiaries = 1; byte[] input = makeBulkDepositForInput(contract, numBeneficiaries, BigInteger.TEN); @@ -3038,8 +3086,8 @@ public void testBulkDepositForInputTooShort() { @Test public void testBulkDepositForInputTooLong() { - AionAddress acct = getNewExistentAccount(BigInteger.ONE); - AionAddress contract = createTRScontract(acct, false, false, 1, BigInteger.ZERO, 0); + Address acct = getNewExistentAccount(BigInteger.ONE); + Address contract = createTRScontract(acct, false, false, 1, BigInteger.ZERO, 0); int numBeneficiaries = 100; byte[] input = makeBulkDepositForInput(contract, numBeneficiaries, BigInteger.TEN); @@ -3053,7 +3101,7 @@ public void testBulkDepositForInputTooLong() { @Test public void testBulkDepositForContractNonExistent() { int numBeneficiaries = 3; - AionAddress acct = getNewExistentAccount(BigInteger.ONE); + Address acct = getNewExistentAccount(BigInteger.ONE); byte[] input = makeBulkDepositForInput(acct, numBeneficiaries, BigInteger.TEN); assertEquals( PrecompiledResultCode.FAILURE, @@ -3063,9 +3111,9 @@ public void testBulkDepositForContractNonExistent() { @Test public void testBulkDepositForCallerIsNotOwner() { int numBeneficiaries = 5; - AionAddress acct = getNewExistentAccount(BigInteger.ONE); - AionAddress contract = createTRScontract(acct, false, false, 1, BigInteger.ZERO, 0); - AionAddress whoami = + Address acct = getNewExistentAccount(BigInteger.ONE); + Address contract = createTRScontract(acct, false, false, 1, BigInteger.ZERO, 0); + Address whoami = getNewExistentAccount( BigInteger.TEN.multiply(BigInteger.valueOf(numBeneficiaries))); byte[] input = makeBulkDepositForInput(contract, numBeneficiaries, BigInteger.TEN); @@ -3077,8 +3125,8 @@ public void testBulkDepositForCallerIsNotOwner() { @Test public void testBulkDepositForContractLocked() { int numBeneficiaries = 4; - AionAddress acct = getNewExistentAccount(BigInteger.ONE); - AionAddress contract = createAndLockTRScontract(acct, false, false, 1, BigInteger.ZERO, 0); + Address acct = getNewExistentAccount(BigInteger.ONE); + Address contract = createAndLockTRScontract(acct, false, false, 1, BigInteger.ZERO, 0); byte[] input = makeBulkDepositForInput(contract, numBeneficiaries, BigInteger.TEN); assertEquals( PrecompiledResultCode.FAILURE, @@ -3088,8 +3136,8 @@ public void testBulkDepositForContractLocked() { @Test public void testBulkDepositForContractLive() { int numBeneficiaries = 7; - AionAddress acct = getNewExistentAccount(BigInteger.ONE); - AionAddress contract = + Address acct = getNewExistentAccount(BigInteger.ONE); + Address contract = createLockedAndLiveTRScontract(acct, false, false, 1, BigInteger.ZERO, 0); byte[] input = makeBulkDepositForInput(contract, numBeneficiaries, BigInteger.TEN); assertEquals( @@ -3100,13 +3148,13 @@ public void testBulkDepositForContractLive() { @Test public void testBulkDepositForZeroBeneficiaries() { int numBeneficiaries = 1; - AionAddress acct = getNewExistentAccount(BigInteger.ONE); - AionAddress contract = createTRScontract(acct, false, false, 1, BigInteger.ZERO, 0); + Address acct = getNewExistentAccount(BigInteger.ONE); + Address contract = createTRScontract(acct, false, false, 1, BigInteger.ZERO, 0); byte[] input = makeBulkDepositForInput(contract, numBeneficiaries, BigInteger.TEN); // Remove the 1 beneficiary. byte[] noBeneficiaries = new byte[33]; - System.arraycopy(input, 0, noBeneficiaries, 0, AionAddress.SIZE + 1); + System.arraycopy(input, 0, noBeneficiaries, 0, Address.SIZE + 1); assertEquals( PrecompiledResultCode.FAILURE, newTRSuseContract(acct).execute(noBeneficiaries, COST).getResultCode()); @@ -3115,8 +3163,8 @@ public void testBulkDepositForZeroBeneficiaries() { @Test public void testBulkDepositForBeneficiaryLengthOff() { int numBeneficiaries = 1; - AionAddress acct = getNewExistentAccount(BigInteger.ONE); - AionAddress contract = createTRScontract(acct, false, false, 1, BigInteger.ZERO, 0); + Address acct = getNewExistentAccount(BigInteger.ONE); + Address contract = createTRScontract(acct, false, false, 1, BigInteger.ZERO, 0); byte[] input = makeBulkDepositForInput(contract, numBeneficiaries, BigInteger.TEN); // Remove the last byte of the array. @@ -3138,17 +3186,17 @@ public void testBulkDepositForBeneficiaryLengthOff() { public void testBulkDepositForSelfIncluded() { int numBeneficiaries = 12; BigInteger deposits = new BigInteger("3462363223"); - AionAddress owner = + Address owner = getNewExistentAccount(deposits.multiply(BigInteger.valueOf(numBeneficiaries + 1))); - AionAddress contract = createTRScontract(owner, false, false, 1, BigInteger.ZERO, 0); + Address contract = createTRScontract(owner, false, false, 1, BigInteger.ZERO, 0); byte[] input = makeBulkDepositForInputwithSelf(contract, owner, numBeneficiaries, deposits); AbstractTRS trs = newTRSuseContract(owner); assertEquals(PrecompiledResultCode.SUCCESS, trs.execute(input, COST).getResultCode()); - Set contributors = getAllDepositors(trs, contract); + Set
contributors = getAllDepositors(trs, contract); assertEquals(numBeneficiaries + 1, contributors.size()); assertTrue(contributors.contains(owner)); - for (AionAddress acc : contributors) { + for (Address acc : contributors) { assertEquals(deposits, getDepositBalance(trs, contract, acc)); } assertEquals( @@ -3159,13 +3207,13 @@ public void testBulkDepositForSelfIncluded() { @Test public void testBulkDepositForOneBeneficiary() { BigInteger deposits = new BigInteger("111112222"); - AionAddress owner = getNewExistentAccount(deposits); - AionAddress contract = createTRScontract(owner, false, false, 1, BigInteger.ZERO, 0); + Address owner = getNewExistentAccount(deposits); + Address contract = createTRScontract(owner, false, false, 1, BigInteger.ZERO, 0); byte[] input = makeBulkDepositForInput(contract, 1, deposits); AbstractTRS trs = newTRSuseContract(owner); assertEquals(PrecompiledResultCode.SUCCESS, trs.execute(input, COST).getResultCode()); - Set contributors = getAllDepositors(trs, contract); + Set
contributors = getAllDepositors(trs, contract); assertEquals(1, contributors.size()); assertEquals(deposits, getDepositBalance(trs, contract, contributors.iterator().next())); assertEquals(deposits, getTotalBalance(trs, contract)); @@ -3175,15 +3223,15 @@ public void testBulkDepositForOneBeneficiary() { public void testBulkDepositFor100Beneficiaries() { BigInteger deposits = new BigInteger("345654399"); BigInteger total = deposits.multiply(BigInteger.valueOf(100)); - AionAddress owner = getNewExistentAccount(total); - AionAddress contract = createTRScontract(owner, false, false, 1, BigInteger.ZERO, 0); + Address owner = getNewExistentAccount(total); + Address contract = createTRScontract(owner, false, false, 1, BigInteger.ZERO, 0); byte[] input = makeBulkDepositForInput(contract, 100, deposits); AbstractTRS trs = newTRSuseContract(owner); assertEquals(PrecompiledResultCode.SUCCESS, trs.execute(input, COST).getResultCode()); - Set contributors = getAllDepositors(trs, contract); + Set
contributors = getAllDepositors(trs, contract); assertEquals(100, contributors.size()); - for (AionAddress acc : contributors) { + for (Address acc : contributors) { assertEquals(deposits, getDepositBalance(trs, contract, acc)); } assertEquals(total, getTotalBalance(trs, contract)); @@ -3194,13 +3242,15 @@ public void testBulkDepositForInsufficientFundsFirstDeposit() { int numBeneficiaries = 13; BigInteger deposits = new BigInteger("111112222"); BigInteger amt = deposits.subtract(BigInteger.ONE); - AionAddress owner = getNewExistentAccount(amt); - AionAddress contract = createTRScontract(owner, false, false, 1, BigInteger.ZERO, 0); + Address owner = getNewExistentAccount(amt); + Address contract = createTRScontract(owner, false, false, 1, BigInteger.ZERO, 0); AbstractTRS trs = newTRSuseContract(owner); byte[] input = makeBulkDepositForInput(contract, numBeneficiaries, deposits); - assertEquals(PrecompiledResultCode.INSUFFICIENT_BALANCE, trs.execute(input, COST).getResultCode()); - Set contributors = getAllDepositors(trs, contract); + assertEquals( + PrecompiledResultCode.INSUFFICIENT_BALANCE, + trs.execute(input, COST).getResultCode()); + Set
contributors = getAllDepositors(trs, contract); assertTrue(contributors.isEmpty()); assertEquals(BigInteger.ZERO, getTotalBalance(trs, contract)); } @@ -3211,13 +3261,15 @@ public void testBulkDepositForInsufficientFundsLastDeposit() { BigInteger deposits = new BigInteger("111112222"); BigInteger amt = (deposits.multiply(BigInteger.valueOf(numBeneficiaries))).subtract(BigInteger.ONE); - AionAddress owner = getNewExistentAccount(amt); - AionAddress contract = createTRScontract(owner, false, false, 1, BigInteger.ZERO, 0); + Address owner = getNewExistentAccount(amt); + Address contract = createTRScontract(owner, false, false, 1, BigInteger.ZERO, 0); AbstractTRS trs = newTRSuseContract(owner); byte[] input = makeBulkDepositForInput(contract, numBeneficiaries, deposits); - assertEquals(PrecompiledResultCode.INSUFFICIENT_BALANCE, trs.execute(input, COST).getResultCode()); - Set contributors = getAllDepositors(trs, contract); + assertEquals( + PrecompiledResultCode.INSUFFICIENT_BALANCE, + trs.execute(input, COST).getResultCode()); + Set
contributors = getAllDepositors(trs, contract); assertTrue(contributors.isEmpty()); assertEquals(BigInteger.ZERO, getTotalBalance(trs, contract)); } @@ -3230,14 +3282,14 @@ public void testBulkDepositForInsufficientFundsMidDeposit() { BigInteger amt = deposits.multiply( BigInteger.valueOf(numBeneficiaries - diff).subtract(BigInteger.ONE)); - AionAddress owner = getNewExistentAccount(amt); - AionAddress contract = createTRScontract(owner, false, false, 1, BigInteger.ZERO, 0); + Address owner = getNewExistentAccount(amt); + Address contract = createTRScontract(owner, false, false, 1, BigInteger.ZERO, 0); AbstractTRS trs = newTRSuseContract(owner); byte[] input = makeBulkDepositForInput(contract, numBeneficiaries - diff - 1, deposits); assertEquals(PrecompiledResultCode.SUCCESS, trs.execute(input, COST).getResultCode()); - Set contributors = getAllDepositors(trs, contract); - for (AionAddress acc : contributors) { + Set
contributors = getAllDepositors(trs, contract); + for (Address acc : contributors) { assertEquals(deposits, getDepositBalance(trs, contract, acc)); } assertEquals( @@ -3246,11 +3298,13 @@ public void testBulkDepositForInsufficientFundsMidDeposit() { // Verify no one received any deposits and that previous total is unchanged. input = makeBulkDepositForInput(contract, diff, deposits); - assertEquals(PrecompiledResultCode.INSUFFICIENT_BALANCE, trs.execute(input, COST).getResultCode()); - Set contributors2 = getAllDepositors(trs, contract); + assertEquals( + PrecompiledResultCode.INSUFFICIENT_BALANCE, + trs.execute(input, COST).getResultCode()); + Set
contributors2 = getAllDepositors(trs, contract); assertEquals(contributors.size(), contributors2.size()); assertEquals(contributors, contributors2); - for (AionAddress acc : contributors) { + for (Address acc : contributors) { assertEquals(deposits, getDepositBalance(trs, contract, acc)); } assertEquals( diff --git a/modPrecompiled/test/org/aion/precompiled/contracts/ATB/BridgeControllerOwnerTest.java b/modPrecompiled/test/org/aion/precompiled/contracts/ATB/BridgeControllerOwnerTest.java index 4004427e44..907fa190b4 100644 --- a/modPrecompiled/test/org/aion/precompiled/contracts/ATB/BridgeControllerOwnerTest.java +++ b/modPrecompiled/test/org/aion/precompiled/contracts/ATB/BridgeControllerOwnerTest.java @@ -7,8 +7,9 @@ import org.aion.base.type.AionAddress; import org.aion.base.util.ByteUtil; import org.aion.crypto.HashUtil; -import org.aion.precompiled.contracts.DummyRepo; import org.aion.fastvm.ExecutionContext; +import org.aion.precompiled.contracts.DummyRepo; +import org.aion.vm.api.interfaces.Address; import org.aion.vm.api.interfaces.IExecutionLog; import org.aion.vm.api.interfaces.TransactionSideEffects; import org.junit.Before; @@ -20,9 +21,10 @@ public class BridgeControllerOwnerTest { private BridgeController controller; private TransactionSideEffects result; - private static final AionAddress CONTRACT_ADDR = + private static final Address CONTRACT_ADDR = new AionAddress(HashUtil.h256("contractAddress".getBytes())); - private static final AionAddress OWNER_ADDR = new AionAddress(HashUtil.h256("ownerAddress".getBytes())); + private static final Address OWNER_ADDR = + new AionAddress(HashUtil.h256("ownerAddress".getBytes())); @Before public void beforeEach() { diff --git a/modPrecompiled/test/org/aion/precompiled/contracts/ATB/BridgeControllerRingTest.java b/modPrecompiled/test/org/aion/precompiled/contracts/ATB/BridgeControllerRingTest.java index a63acaedf4..e77e987b3d 100644 --- a/modPrecompiled/test/org/aion/precompiled/contracts/ATB/BridgeControllerRingTest.java +++ b/modPrecompiled/test/org/aion/precompiled/contracts/ATB/BridgeControllerRingTest.java @@ -8,6 +8,7 @@ import org.aion.crypto.ECKeyFac; import org.aion.crypto.HashUtil; import org.aion.precompiled.contracts.DummyRepo; +import org.aion.vm.api.interfaces.Address; import org.junit.Before; import org.junit.Test; @@ -15,9 +16,10 @@ public class BridgeControllerRingTest { private BridgeStorageConnector connector; private BridgeController controller; - private static final AionAddress CONTRACT_ADDR = + private static final Address CONTRACT_ADDR = new AionAddress(HashUtil.h256("contractAddress".getBytes())); - private static final AionAddress OWNER_ADDR = new AionAddress(HashUtil.h256("ownerAddress".getBytes())); + private static final Address OWNER_ADDR = + new AionAddress(HashUtil.h256("ownerAddress".getBytes())); private static final ECKey members[] = new ECKey[] { @@ -41,7 +43,8 @@ public void beforeEach() { DummyRepo repo = new DummyRepo(); this.connector = new BridgeStorageConnector(repo, CONTRACT_ADDR); this.controller = - new BridgeController(connector, dummyContext().getSideEffects(), CONTRACT_ADDR, OWNER_ADDR); + new BridgeController( + connector, dummyContext().getSideEffects(), CONTRACT_ADDR, OWNER_ADDR); this.controller.initialize(); byte[][] memberList = new byte[members.length][]; diff --git a/modPrecompiled/test/org/aion/precompiled/contracts/ATB/BridgeRingInitializationTest.java b/modPrecompiled/test/org/aion/precompiled/contracts/ATB/BridgeRingInitializationTest.java index c171d783c6..6b014b31ff 100644 --- a/modPrecompiled/test/org/aion/precompiled/contracts/ATB/BridgeRingInitializationTest.java +++ b/modPrecompiled/test/org/aion/precompiled/contracts/ATB/BridgeRingInitializationTest.java @@ -6,6 +6,7 @@ import org.aion.base.type.AionAddress; import org.aion.crypto.HashUtil; import org.aion.precompiled.contracts.DummyRepo; +import org.aion.vm.api.interfaces.Address; import org.junit.Before; import org.junit.Test; @@ -13,16 +14,18 @@ public class BridgeRingInitializationTest { private BridgeStorageConnector connector; private BridgeController controller; - private static final AionAddress CONTRACT_ADDR = + private static final Address CONTRACT_ADDR = new AionAddress(HashUtil.h256("contractAddress".getBytes())); - private static final AionAddress OWNER_ADDR = new AionAddress(HashUtil.h256("ownerAddress".getBytes())); + private static final Address OWNER_ADDR = + new AionAddress(HashUtil.h256("ownerAddress".getBytes())); @Before public void beforeEach() { DummyRepo repo = new DummyRepo(); this.connector = new BridgeStorageConnector(repo, CONTRACT_ADDR); this.controller = - new BridgeController(connector, dummyContext().getSideEffects(), CONTRACT_ADDR, OWNER_ADDR); + new BridgeController( + connector, dummyContext().getSideEffects(), CONTRACT_ADDR, OWNER_ADDR); this.controller.initialize(); } diff --git a/modPrecompiled/test/org/aion/precompiled/contracts/ATB/BridgeStorageConnectorTest.java b/modPrecompiled/test/org/aion/precompiled/contracts/ATB/BridgeStorageConnectorTest.java index b579388fb2..6a7bb6bc35 100644 --- a/modPrecompiled/test/org/aion/precompiled/contracts/ATB/BridgeStorageConnectorTest.java +++ b/modPrecompiled/test/org/aion/precompiled/contracts/ATB/BridgeStorageConnectorTest.java @@ -7,12 +7,13 @@ import org.aion.base.util.ByteUtil; import org.aion.crypto.HashUtil; import org.aion.precompiled.contracts.DummyRepo; +import org.aion.vm.api.interfaces.Address; import org.junit.Before; import org.junit.Test; public class BridgeStorageConnectorTest { private BridgeStorageConnector connector; - private static final AionAddress contractAddress = AionAddress.ZERO_ADDRESS(); + private static final Address contractAddress = AionAddress.ZERO_ADDRESS(); @Before public void beforeEach() { diff --git a/modPrecompiled/test/org/aion/precompiled/contracts/ATB/BridgeTestUtils.java b/modPrecompiled/test/org/aion/precompiled/contracts/ATB/BridgeTestUtils.java index ffb889d010..76905b2105 100644 --- a/modPrecompiled/test/org/aion/precompiled/contracts/ATB/BridgeTestUtils.java +++ b/modPrecompiled/test/org/aion/precompiled/contracts/ATB/BridgeTestUtils.java @@ -5,17 +5,18 @@ import org.aion.crypto.HashUtil; import org.aion.fastvm.ExecutionContext; import org.aion.mcf.vm.types.DataWord; +import org.aion.vm.api.interfaces.Address; public class BridgeTestUtils { static ExecutionContext dummyContext() { return context(AionAddress.ZERO_ADDRESS(), AionAddress.ZERO_ADDRESS(), new byte[0]); } - static ExecutionContext context(AionAddress from, AionAddress to, byte[] txData) { + static ExecutionContext context(Address from, Address to, byte[] txData) { final byte[] transactionHash = HashUtil.h256("transaction".getBytes()); - final AionAddress address = to; - final AionAddress origin = from; - final AionAddress caller = origin; + final Address address = to; + final Address origin = from; + final Address caller = origin; final DataWord nrgPrice = DataWord.ONE; final long nrgLimit = 21000L; final DataWord callValue = DataWord.ZERO; @@ -23,7 +24,7 @@ static ExecutionContext context(AionAddress from, AionAddress to, byte[] txData) final int callDepth = 1; final int flag = 0; final int kind = 0; - final AionAddress blockCoinbase = + final Address blockCoinbase = new AionAddress( AddressSpecs.computeA0Address(HashUtil.h256("coinbase".getBytes()))); long blockNumber = 0; diff --git a/modPrecompiled/test/org/aion/precompiled/contracts/ATB/BridgeTransferTest.java b/modPrecompiled/test/org/aion/precompiled/contracts/ATB/BridgeTransferTest.java index 3c14fc9c35..9bbf82b726 100644 --- a/modPrecompiled/test/org/aion/precompiled/contracts/ATB/BridgeTransferTest.java +++ b/modPrecompiled/test/org/aion/precompiled/contracts/ATB/BridgeTransferTest.java @@ -10,9 +10,10 @@ import org.aion.crypto.ECKey; import org.aion.crypto.ECKeyFac; import org.aion.crypto.HashUtil; -import org.aion.precompiled.contracts.DummyRepo; -import org.aion.precompiled.PrecompiledUtilities; import org.aion.fastvm.ExecutionContext; +import org.aion.precompiled.PrecompiledUtilities; +import org.aion.precompiled.contracts.DummyRepo; +import org.aion.vm.api.interfaces.Address; import org.aion.vm.api.interfaces.IExecutionLog; import org.junit.Before; import org.junit.Test; @@ -25,9 +26,10 @@ public class BridgeTransferTest { private TokenBridgeContract contract; private ExecutionContext context; - private static final AionAddress CONTRACT_ADDR = + private static final Address CONTRACT_ADDR = new AionAddress(HashUtil.h256("contractAddress".getBytes())); - private static final AionAddress OWNER_ADDR = new AionAddress(HashUtil.h256("ownerAddress".getBytes())); + private static final Address OWNER_ADDR = + new AionAddress(HashUtil.h256("ownerAddress".getBytes())); private static final ECKey members[] = new ECKey[] { diff --git a/modPrecompiled/test/org/aion/precompiled/contracts/ATB/TokenBridgeContractTest.java b/modPrecompiled/test/org/aion/precompiled/contracts/ATB/TokenBridgeContractTest.java index 352c16bd6a..cd74f955c0 100644 --- a/modPrecompiled/test/org/aion/precompiled/contracts/ATB/TokenBridgeContractTest.java +++ b/modPrecompiled/test/org/aion/precompiled/contracts/ATB/TokenBridgeContractTest.java @@ -13,17 +13,17 @@ import org.aion.crypto.ECKey; import org.aion.crypto.ECKeyFac; import org.aion.crypto.HashUtil; +import org.aion.fastvm.ExecutionContext; import org.aion.mcf.vm.types.DataWord; import org.aion.precompiled.PrecompiledResultCode; import org.aion.precompiled.PrecompiledTransactionResult; -import org.aion.precompiled.contracts.DummyRepo; import org.aion.precompiled.PrecompiledUtilities; import org.aion.precompiled.contracts.DummyRepo; import org.aion.precompiled.encoding.AbiEncoder; import org.aion.precompiled.encoding.AddressFVM; import org.aion.precompiled.encoding.ListFVM; import org.aion.precompiled.encoding.Uint128FVM; -import org.aion.fastvm.ExecutionContext; +import org.aion.vm.api.interfaces.Address; import org.aion.vm.api.interfaces.IExecutionLog; import org.aion.vm.api.interfaces.InternalTransactionInterface; import org.junit.Before; @@ -48,9 +48,10 @@ public class TokenBridgeContractTest { ECKeyFac.inst().create() }; - private static final AionAddress CONTRACT_ADDR = + private static final Address CONTRACT_ADDR = new AionAddress(HashUtil.h256("contractAddress".getBytes())); - private static final AionAddress OWNER_ADDR = new AionAddress(HashUtil.h256("ownerAddress".getBytes())); + private static final Address OWNER_ADDR = + new AionAddress(HashUtil.h256("ownerAddress".getBytes())); private static final long DEFAULT_NRG = 21000L; @@ -118,7 +119,10 @@ public void testGetNewOwnerNotOwnerAddress() { // override defaults this.contract = new TokenBridgeContract( - context(AionAddress.ZERO_ADDRESS(), CONTRACT_ADDR, ByteUtil.EMPTY_BYTE_ARRAY), + context( + AionAddress.ZERO_ADDRESS(), + CONTRACT_ADDR, + ByteUtil.EMPTY_BYTE_ARRAY), this.repository, OWNER_ADDR, CONTRACT_ADDR); @@ -171,7 +175,10 @@ public void testInitializeRingNotOwner() { // override defaults this.contract = new TokenBridgeContract( - context(AionAddress.ZERO_ADDRESS(), CONTRACT_ADDR, ByteUtil.EMPTY_BYTE_ARRAY), + context( + AionAddress.ZERO_ADDRESS(), + CONTRACT_ADDR, + ByteUtil.EMPTY_BYTE_ARRAY), this.repository, OWNER_ADDR, CONTRACT_ADDR); @@ -217,9 +224,9 @@ public void testTransfer() { new AddressFVM(new ByteArrayWrapper(members[0].getAddress()))) .encodeBytes(); - PrecompiledTransactionResult transferResult = this.contract.execute(callPayload, DEFAULT_NRG); - assertThat(transferResult.getResultCode()) - .isEqualTo(PrecompiledResultCode.SUCCESS); + PrecompiledTransactionResult transferResult = + this.contract.execute(callPayload, DEFAULT_NRG); + assertThat(transferResult.getResultCode()).isEqualTo(PrecompiledResultCode.SUCCESS); // override defaults this.repository.addBalance(CONTRACT_ADDR, BigInteger.TEN); @@ -323,8 +330,7 @@ public void testTransfer() { .getOutput()) .isEqualTo(submitBundleContext.getTransactionHash()); - assertThat(transferResult.getResultCode()) - .isEqualTo(PrecompiledResultCode.SUCCESS); + assertThat(transferResult.getResultCode()).isEqualTo(PrecompiledResultCode.SUCCESS); for (BridgeTransfer b : transfers) { assertThat(this.repository.getBalance(new AionAddress(b.getRecipient()))) @@ -337,9 +343,11 @@ public void testTransfer() { // 10 internal transactions (that all succeed) // 10 Distributed events // 1 ProcessedBundle Event - assertThat(submitBundleContext.getSideEffects().getInternalTransactions().size()).isEqualTo(10); + assertThat(submitBundleContext.getSideEffects().getInternalTransactions().size()) + .isEqualTo(10); i = 0; - for (InternalTransactionInterface tx : submitBundleContext.getSideEffects().getInternalTransactions()) { + for (InternalTransactionInterface tx : + submitBundleContext.getSideEffects().getInternalTransactions()) { // verify the internal transaction is not rejected assertThat(tx.isRejected()).isFalse(); @@ -351,7 +359,8 @@ public void testTransfer() { assertThat(new BigInteger(1, tx.getValue()).intValueExact()).isEqualTo(1); // verify that the recipient is what we intended (in the order we submitted) - assertThat(tx.getDestinationAddress()).isEqualTo(new AionAddress(transfers[i].getRecipient())); + assertThat(tx.getDestinationAddress()) + .isEqualTo(new AionAddress(transfers[i].getRecipient())); i++; } @@ -409,9 +418,9 @@ public void testNonA0AddressTransfer() { new AddressFVM(new ByteArrayWrapper(members[0].getAddress()))) .encodeBytes(); - PrecompiledTransactionResult transferResult = this.contract.execute(callPayload, DEFAULT_NRG); - assertThat(transferResult.getResultCode()) - .isEqualTo(PrecompiledResultCode.SUCCESS); + PrecompiledTransactionResult transferResult = + this.contract.execute(callPayload, DEFAULT_NRG); + assertThat(transferResult.getResultCode()).isEqualTo(PrecompiledResultCode.SUCCESS); // override defaults this.repository.addBalance(CONTRACT_ADDR, BigInteger.TEN); @@ -514,8 +523,7 @@ public void testNonA0AddressTransfer() { .getOutput()) .isEqualTo(submitBundleContext.getTransactionHash()); - assertThat(transferResult.getResultCode()) - .isEqualTo(PrecompiledResultCode.SUCCESS); + assertThat(transferResult.getResultCode()).isEqualTo(PrecompiledResultCode.SUCCESS); for (BridgeTransfer b : transfers) { assertThat(this.repository.getBalance(new AionAddress(b.getRecipient()))) @@ -528,9 +536,11 @@ public void testNonA0AddressTransfer() { // 10 internal transactions (that all succeed) // 10 Distributed events // 1 ProcessedBundle Event - assertThat(submitBundleContext.getSideEffects().getInternalTransactions().size()).isEqualTo(10); + assertThat(submitBundleContext.getSideEffects().getInternalTransactions().size()) + .isEqualTo(10); i = 0; - for (InternalTransactionInterface tx : submitBundleContext.getSideEffects().getInternalTransactions()) { + for (InternalTransactionInterface tx : + submitBundleContext.getSideEffects().getInternalTransactions()) { // verify the internal transaction is not rejected assertThat(tx.isRejected()).isFalse(); @@ -542,7 +552,8 @@ public void testNonA0AddressTransfer() { assertThat(new BigInteger(1, tx.getValue()).intValueExact()).isEqualTo(1); // verify that the recipient is what we intended (in the order we submitted) - assertThat(tx.getDestinationAddress()).isEqualTo(new AionAddress(transfers[i].getRecipient())); + assertThat(tx.getDestinationAddress()) + .isEqualTo(new AionAddress(transfers[i].getRecipient())); i++; } @@ -600,9 +611,9 @@ public void testTransferNotRelayer() { new AddressFVM(new ByteArrayWrapper(members[0].getAddress()))) .encodeBytes(); - PrecompiledTransactionResult transferResult = this.contract.execute(callPayload, DEFAULT_NRG); - assertThat(transferResult.getResultCode()) - .isEqualTo(PrecompiledResultCode.SUCCESS); + PrecompiledTransactionResult transferResult = + this.contract.execute(callPayload, DEFAULT_NRG); + assertThat(transferResult.getResultCode()).isEqualTo(PrecompiledResultCode.SUCCESS); // override defaults this.repository.addBalance(CONTRACT_ADDR, BigInteger.TEN); @@ -703,8 +714,7 @@ public void testTransferNotRelayer() { sigChunk3) .encodeBytes(); transferResult = this.contract.execute(callPayload, DEFAULT_NRG); - assertThat(transferResult.getResultCode()) - .isEqualTo(PrecompiledResultCode.FAILURE); + assertThat(transferResult.getResultCode()).isEqualTo(PrecompiledResultCode.FAILURE); } @Test @@ -736,9 +746,9 @@ public void testTransfersGreaterThanMaxListSize() { new AddressFVM(new ByteArrayWrapper(members[0].getAddress()))) .encodeBytes(); - PrecompiledTransactionResult transferResult = this.contract.execute(callPayload, DEFAULT_NRG); - assertThat(transferResult.getResultCode()) - .isEqualTo(PrecompiledResultCode.SUCCESS); + PrecompiledTransactionResult transferResult = + this.contract.execute(callPayload, DEFAULT_NRG); + assertThat(transferResult.getResultCode()).isEqualTo(PrecompiledResultCode.SUCCESS); // override defaults ExecutionContext submitBundleContext = @@ -815,8 +825,7 @@ public void testTransfersGreaterThanMaxListSize() { /// VERIFICATION - assertThat(transferResult.getResultCode()) - .isEqualTo(PrecompiledResultCode.FAILURE); + assertThat(transferResult.getResultCode()).isEqualTo(PrecompiledResultCode.FAILURE); for (BridgeTransfer b : transfers) { assertThat(this.repository.getBalance(new AionAddress(b.getRecipient()))) @@ -856,9 +865,9 @@ public void testAlreadySubmittedBundle() { new AddressFVM(new ByteArrayWrapper(members[0].getAddress()))) .encodeBytes(); - PrecompiledTransactionResult transferResult = this.contract.execute(callPayload, DEFAULT_NRG); - assertThat(transferResult.getResultCode()) - .isEqualTo(PrecompiledResultCode.SUCCESS); + PrecompiledTransactionResult transferResult = + this.contract.execute(callPayload, DEFAULT_NRG); + assertThat(transferResult.getResultCode()).isEqualTo(PrecompiledResultCode.SUCCESS); // override defaults this.repository.addBalance(CONTRACT_ADDR, BigInteger.TEN); @@ -940,16 +949,27 @@ public void testAlreadySubmittedBundle() { transferResult = this.contract.execute(callPayload, DEFAULT_NRG); /// VERIFICATION - assertThat(transferResult.getResultCode()) - .isEqualTo(PrecompiledResultCode.SUCCESS); + assertThat(transferResult.getResultCode()).isEqualTo(PrecompiledResultCode.SUCCESS); assertThat(submitBundleContext.getSideEffects().getInternalTransactions()).isEmpty(); assertThat(submitBundleContext.getSideEffects().getExecutionLogs().size()).isEqualTo(1); // ATB 4.1 check that proper event was emit - assertThat(submitBundleContext.getSideEffects().getExecutionLogs().get(0).getLogTopics().get(0)) + assertThat( + submitBundleContext + .getSideEffects() + .getExecutionLogs() + .get(0) + .getLogTopics() + .get(0)) .isEqualTo(BridgeEventSig.SUCCESSFUL_TXHASH.getHashed()); - assertThat(submitBundleContext.getSideEffects().getExecutionLogs().get(0).getLogTopics().get(1)) + assertThat( + submitBundleContext + .getSideEffects() + .getExecutionLogs() + .get(0) + .getLogTopics() + .get(1)) .isEqualTo(submitBundleContext.getTransactionHash()); } @@ -979,9 +999,9 @@ public void testTransferRingLocked() { new AddressFVM(new ByteArrayWrapper(members[0].getAddress()))) .encodeBytes(); - PrecompiledTransactionResult transferResult = this.contract.execute(callPayload, DEFAULT_NRG); - assertThat(transferResult.getResultCode()) - .isEqualTo(PrecompiledResultCode.SUCCESS); + PrecompiledTransactionResult transferResult = + this.contract.execute(callPayload, DEFAULT_NRG); + assertThat(transferResult.getResultCode()).isEqualTo(PrecompiledResultCode.SUCCESS); // override defaults this.repository.addBalance(CONTRACT_ADDR, BigInteger.TEN); @@ -1082,8 +1102,7 @@ public void testTransferRingLocked() { .getOutput()) .isEqualTo(new byte[32]); - assertThat(transferResult.getResultCode()) - .isEqualTo(PrecompiledResultCode.FAILURE); + assertThat(transferResult.getResultCode()).isEqualTo(PrecompiledResultCode.FAILURE); // check that nothing has been modified from the failed transfer for (BridgeTransfer b : transfers) { @@ -1204,7 +1223,8 @@ public void testTransferInvalidReLayer() { sigChunk2, sigChunk3) .encodeBytes(); - PrecompiledTransactionResult transferResult = this.contract.execute(callPayload, DEFAULT_NRG); + PrecompiledTransactionResult transferResult = + this.contract.execute(callPayload, DEFAULT_NRG); // VERIFICATION - failure assertThat( @@ -1217,8 +1237,7 @@ public void testTransferInvalidReLayer() { .getOutput()) .isEqualTo(new byte[32]); - assertThat(transferResult.getResultCode()) - .isEqualTo(PrecompiledResultCode.FAILURE); + assertThat(transferResult.getResultCode()).isEqualTo(PrecompiledResultCode.FAILURE); // check that nothing has been modified from the failed transfer for (BridgeTransfer b : transfers) { @@ -1259,9 +1278,9 @@ public void testTransferLessThanMinimumRequiredValidators() { new AddressFVM(new ByteArrayWrapper(members[0].getAddress()))) .encodeBytes(); - PrecompiledTransactionResult transferResult = this.contract.execute(callPayload, DEFAULT_NRG); - assertThat(transferResult.getResultCode()) - .isEqualTo(PrecompiledResultCode.SUCCESS); + PrecompiledTransactionResult transferResult = + this.contract.execute(callPayload, DEFAULT_NRG); + assertThat(transferResult.getResultCode()).isEqualTo(PrecompiledResultCode.SUCCESS); // override defaults this.repository.addBalance(CONTRACT_ADDR, BigInteger.TEN); @@ -1361,8 +1380,7 @@ public void testTransferLessThanMinimumRequiredValidators() { .getOutput()) .isEqualTo(new byte[32]); - assertThat(transferResult.getResultCode()) - .isEqualTo(PrecompiledResultCode.FAILURE); + assertThat(transferResult.getResultCode()).isEqualTo(PrecompiledResultCode.FAILURE); // check that nothing has been modified from the failed transfer for (BridgeTransfer b : transfers) { @@ -1403,9 +1421,9 @@ public void testTransferInsufficientValidatorSignatures() { new AddressFVM(new ByteArrayWrapper(members[0].getAddress()))) .encodeBytes(); - PrecompiledTransactionResult transferResult = this.contract.execute(callPayload, DEFAULT_NRG); - assertThat(transferResult.getResultCode()) - .isEqualTo(PrecompiledResultCode.SUCCESS); + PrecompiledTransactionResult transferResult = + this.contract.execute(callPayload, DEFAULT_NRG); + assertThat(transferResult.getResultCode()).isEqualTo(PrecompiledResultCode.SUCCESS); // override defaults this.repository.addBalance(CONTRACT_ADDR, BigInteger.TEN); @@ -1507,8 +1525,7 @@ public void testTransferInsufficientValidatorSignatures() { .getOutput()) .isEqualTo(new byte[32]); - assertThat(transferResult.getResultCode()) - .isEqualTo(PrecompiledResultCode.FAILURE); + assertThat(transferResult.getResultCode()).isEqualTo(PrecompiledResultCode.FAILURE); // check that nothing has been changed from the failed transfer for (BridgeTransfer b : transfers) { @@ -1550,9 +1567,9 @@ public void testTransferOutOfBoundsListMeta() { new AddressFVM(new ByteArrayWrapper(members[0].getAddress()))) .encodeBytes(); - PrecompiledTransactionResult transferResult = this.contract.execute(callPayload, DEFAULT_NRG); - assertThat(transferResult.getResultCode()) - .isEqualTo(PrecompiledResultCode.SUCCESS); + PrecompiledTransactionResult transferResult = + this.contract.execute(callPayload, DEFAULT_NRG); + assertThat(transferResult.getResultCode()).isEqualTo(PrecompiledResultCode.SUCCESS); // override defaults this.repository.addBalance(CONTRACT_ADDR, BigInteger.TEN); @@ -1657,8 +1674,7 @@ public void testTransferOutOfBoundsListMeta() { .getOutput()) .isEqualTo(new byte[32]); - assertThat(transferResult.getResultCode()) - .isEqualTo(PrecompiledResultCode.FAILURE); + assertThat(transferResult.getResultCode()).isEqualTo(PrecompiledResultCode.FAILURE); // check that nothing has been changed from the failed transfer for (BridgeTransfer b : transfers) { @@ -1705,12 +1721,12 @@ public void testTransferToSameAddressTwiceInOneBundle() { byte[] payloadHash = fromSetup.payloadHash; byte[] callPayload = fromSetup.callPayload; - PrecompiledTransactionResult transferResult = this.contract.execute(callPayload, DEFAULT_NRG); + PrecompiledTransactionResult transferResult = + this.contract.execute(callPayload, DEFAULT_NRG); /// VERIFICATION - assertThat(transferResult.getResultCode()) - .isEqualTo(PrecompiledResultCode.SUCCESS); + assertThat(transferResult.getResultCode()).isEqualTo(PrecompiledResultCode.SUCCESS); int i = 0; for (BridgeTransfer b : transfers) { @@ -1730,9 +1746,11 @@ public void testTransferToSameAddressTwiceInOneBundle() { // 10 internal transactions (that all succeed) // 10 Distributed events // 1 ProcessedBundle Event - assertThat(submitBundleContext.getSideEffects().getInternalTransactions().size()).isEqualTo(10); + assertThat(submitBundleContext.getSideEffects().getInternalTransactions().size()) + .isEqualTo(10); i = 0; - for (InternalTransactionInterface tx : submitBundleContext.getSideEffects().getInternalTransactions()) { + for (InternalTransactionInterface tx : + submitBundleContext.getSideEffects().getInternalTransactions()) { // verify the internal transaction is not rejected assertThat(tx.isRejected()).isFalse(); @@ -1744,7 +1762,8 @@ public void testTransferToSameAddressTwiceInOneBundle() { assertThat(new BigInteger(1, tx.getValue()).intValueExact()).isEqualTo(1); // verify that the recipient is what we intended (in the order we submitted) - assertThat(tx.getDestinationAddress()).isEqualTo(new AionAddress(transfers[i].getRecipient())); + assertThat(tx.getDestinationAddress()) + .isEqualTo(new AionAddress(transfers[i].getRecipient())); i++; } @@ -1797,9 +1816,9 @@ public void testTransferHugeListOffset() { byte[] callPayload = fromSetup.callPayload; callPayload[50] = (byte) 0x128; // make the list offset here too big - PrecompiledTransactionResult transferResult = this.contract.execute(callPayload, DEFAULT_NRG); - assertThat(transferResult.getResultCode()) - .isEqualTo(PrecompiledResultCode.FAILURE); + PrecompiledTransactionResult transferResult = + this.contract.execute(callPayload, DEFAULT_NRG); + assertThat(transferResult.getResultCode()).isEqualTo(PrecompiledResultCode.FAILURE); // VERIFICATION failure assertThat( @@ -1812,8 +1831,7 @@ public void testTransferHugeListOffset() { .getOutput()) .isEqualTo(new byte[32]); - assertThat(transferResult.getResultCode()) - .isEqualTo(PrecompiledResultCode.FAILURE); + assertThat(transferResult.getResultCode()).isEqualTo(PrecompiledResultCode.FAILURE); // check that nothing has been changed from the failed transfer for (BridgeTransfer b : transfers) { @@ -1848,9 +1866,9 @@ public void testTransferHugeListLength() { byte[] callPayload = fromSetup.callPayload; callPayload[50] = (byte) 0x128; - PrecompiledTransactionResult transferResult = this.contract.execute(callPayload, DEFAULT_NRG); - assertThat(transferResult.getResultCode()) - .isEqualTo(PrecompiledResultCode.FAILURE); + PrecompiledTransactionResult transferResult = + this.contract.execute(callPayload, DEFAULT_NRG); + assertThat(transferResult.getResultCode()).isEqualTo(PrecompiledResultCode.FAILURE); // VERIFICATION failure assertThat( @@ -1863,8 +1881,7 @@ public void testTransferHugeListLength() { .getOutput()) .isEqualTo(new byte[32]); - assertThat(transferResult.getResultCode()) - .isEqualTo(PrecompiledResultCode.FAILURE); + assertThat(transferResult.getResultCode()).isEqualTo(PrecompiledResultCode.FAILURE); // check that nothing has been changed from the failed transfer for (BridgeTransfer b : transfers) { @@ -1906,8 +1923,7 @@ public void testTransferFailLength() { byte[] input = new byte[i]; System.arraycopy(callPayload, 0, input, 0, i); PrecompiledTransactionResult result = this.contract.execute(input, DEFAULT_NRG); - assertThat(result.getResultCode()) - .isEqualTo(PrecompiledResultCode.FAILURE); + assertThat(result.getResultCode()).isEqualTo(PrecompiledResultCode.FAILURE); } System.out.println("fail count: " + i); @@ -1954,8 +1970,7 @@ public void testTransferFailLength2() { byte[] input = new byte[i]; System.arraycopy(callPayload, 0, input, 0, i); PrecompiledTransactionResult result = this.contract.execute(input, DEFAULT_NRG); - assertThat(result.getResultCode()) - .isEqualTo(PrecompiledResultCode.FAILURE); + assertThat(result.getResultCode()).isEqualTo(PrecompiledResultCode.FAILURE); } System.out.println("fail count: " + i); } @@ -1987,9 +2002,9 @@ private ReturnDataFromSetup setupForTest(BridgeTransfer[] transfers, ECKey[] mem new AddressFVM(new ByteArrayWrapper(members[0].getAddress()))) .encodeBytes(); - PrecompiledTransactionResult transferResult = this.contract.execute(callPayload, DEFAULT_NRG); - assertThat(transferResult.getResultCode()) - .isEqualTo(PrecompiledResultCode.SUCCESS); + PrecompiledTransactionResult transferResult = + this.contract.execute(callPayload, DEFAULT_NRG); + assertThat(transferResult.getResultCode()).isEqualTo(PrecompiledResultCode.SUCCESS); // override defaults this.repository.addBalance(CONTRACT_ADDR, BigInteger.TEN); @@ -2103,9 +2118,9 @@ public void testRingLocked() { byte[] callPayload = new AbiEncoder(BridgeFuncSig.PURE_RING_LOCKED.getSignature(), encodingList) .encodeBytes(); - PrecompiledTransactionResult transferResult = this.contract.execute(callPayload, DEFAULT_NRG); - assertThat(transferResult.getResultCode()) - .isEqualTo(PrecompiledResultCode.SUCCESS); + PrecompiledTransactionResult transferResult = + this.contract.execute(callPayload, DEFAULT_NRG); + assertThat(transferResult.getResultCode()).isEqualTo(PrecompiledResultCode.SUCCESS); assertThat(transferResult.getOutput()).isEqualTo(DataWord.ONE.getData()); // lock the ring @@ -2115,9 +2130,9 @@ public void testRingLocked() { byte[] callPayload2 = new AbiEncoder(BridgeFuncSig.PURE_RING_LOCKED.getSignature(), encodingList) .encodeBytes(); - PrecompiledTransactionResult transferResult2 = this.contract.execute(callPayload2, DEFAULT_NRG); - assertThat(transferResult2.getResultCode()) - .isEqualTo(PrecompiledResultCode.SUCCESS); + PrecompiledTransactionResult transferResult2 = + this.contract.execute(callPayload2, DEFAULT_NRG); + assertThat(transferResult2.getResultCode()).isEqualTo(PrecompiledResultCode.SUCCESS); assertThat(transferResult2.getOutput()).isEqualTo(DataWord.ZERO.getData()); } @@ -2148,9 +2163,9 @@ public void testMinThreshold() { byte[] callPayload = new AbiEncoder(BridgeFuncSig.PURE_MIN_THRESH.getSignature(), encodingList) .encodeBytes(); - PrecompiledTransactionResult transferResult = this.contract.execute(callPayload, DEFAULT_NRG); - assertThat(transferResult.getResultCode()) - .isEqualTo(PrecompiledResultCode.SUCCESS); + PrecompiledTransactionResult transferResult = + this.contract.execute(callPayload, DEFAULT_NRG); + assertThat(transferResult.getResultCode()).isEqualTo(PrecompiledResultCode.SUCCESS); assertThat(transferResult.getOutput()) .isEqualTo(new DataWord(new BigInteger("3")).getData()); @@ -2161,9 +2176,9 @@ public void testMinThreshold() { byte[] callPayload2 = new AbiEncoder(BridgeFuncSig.PURE_MIN_THRESH.getSignature(), encodingList) .encodeBytes(); - PrecompiledTransactionResult transferResult2 = this.contract.execute(callPayload2, DEFAULT_NRG); - assertThat(transferResult2.getResultCode()) - .isEqualTo(PrecompiledResultCode.SUCCESS); + PrecompiledTransactionResult transferResult2 = + this.contract.execute(callPayload2, DEFAULT_NRG); + assertThat(transferResult2.getResultCode()).isEqualTo(PrecompiledResultCode.SUCCESS); assertThat(transferResult2.getOutput()) .isEqualTo(new DataWord(new BigInteger("5")).getData()); @@ -2174,9 +2189,9 @@ public void testMinThreshold() { byte[] callPayload3 = new AbiEncoder(BridgeFuncSig.PURE_MIN_THRESH.getSignature(), encodingList) .encodeBytes(); - PrecompiledTransactionResult transferResult3 = this.contract.execute(callPayload3, DEFAULT_NRG); - assertThat(transferResult3.getResultCode()) - .isEqualTo(PrecompiledResultCode.SUCCESS); + PrecompiledTransactionResult transferResult3 = + this.contract.execute(callPayload3, DEFAULT_NRG); + assertThat(transferResult3.getResultCode()).isEqualTo(PrecompiledResultCode.SUCCESS); assertThat(transferResult3.getOutput()) .isEqualTo(new DataWord(new BigInteger("10")).getData()); } @@ -2208,9 +2223,9 @@ public void testMemberCount() { byte[] callPayload = new AbiEncoder(BridgeFuncSig.PURE_MEMBER_COUNT.getSignature(), encodingList) .encodeBytes(); - PrecompiledTransactionResult transferResult = this.contract.execute(callPayload, DEFAULT_NRG); - assertThat(transferResult.getResultCode()) - .isEqualTo(PrecompiledResultCode.SUCCESS); + PrecompiledTransactionResult transferResult = + this.contract.execute(callPayload, DEFAULT_NRG); + assertThat(transferResult.getResultCode()).isEqualTo(PrecompiledResultCode.SUCCESS); assertThat(transferResult.getOutput()) .isEqualTo(new DataWord(new BigInteger("5")).getData()); @@ -2221,9 +2236,9 @@ public void testMemberCount() { byte[] callPayload2 = new AbiEncoder(BridgeFuncSig.PURE_MEMBER_COUNT.getSignature(), encodingList) .encodeBytes(); - PrecompiledTransactionResult transferResult2 = this.contract.execute(callPayload2, DEFAULT_NRG); - assertThat(transferResult2.getResultCode()) - .isEqualTo(PrecompiledResultCode.SUCCESS); + PrecompiledTransactionResult transferResult2 = + this.contract.execute(callPayload2, DEFAULT_NRG); + assertThat(transferResult2.getResultCode()).isEqualTo(PrecompiledResultCode.SUCCESS); assertThat(transferResult2.getOutput()) .isEqualTo(new DataWord(new BigInteger("10")).getData()); } @@ -2261,14 +2276,14 @@ public void testRingMap() { System.arraycopy(randomAddress, 0, callPayload, 4, 32); // execute with valid input - PrecompiledTransactionResult transferResult = this.contract.execute(callPayload, DEFAULT_NRG); - assertThat(transferResult.getResultCode()) - .isEqualTo(PrecompiledResultCode.SUCCESS); + PrecompiledTransactionResult transferResult = + this.contract.execute(callPayload, DEFAULT_NRG); + assertThat(transferResult.getResultCode()).isEqualTo(PrecompiledResultCode.SUCCESS); // execute with invalid input - PrecompiledTransactionResult transferResult2 = this.contract.execute(encodeBytes, DEFAULT_NRG); - assertThat(transferResult2.getResultCode()) - .isEqualTo(PrecompiledResultCode.FAILURE); + PrecompiledTransactionResult transferResult2 = + this.contract.execute(encodeBytes, DEFAULT_NRG); + assertThat(transferResult2.getResultCode()).isEqualTo(PrecompiledResultCode.FAILURE); } @Test @@ -2360,7 +2375,10 @@ public void testAddRingMemberNotOwner() { // override defaults this.contract = new TokenBridgeContract( - context(AionAddress.ZERO_ADDRESS(), CONTRACT_ADDR, ByteUtil.EMPTY_BYTE_ARRAY), + context( + AionAddress.ZERO_ADDRESS(), + CONTRACT_ADDR, + ByteUtil.EMPTY_BYTE_ARRAY), this.repository, OWNER_ADDR, CONTRACT_ADDR); @@ -2509,7 +2527,10 @@ public void testRemoveRingMemberNotOwner() { // override defaults this.contract = new TokenBridgeContract( - context(AionAddress.ZERO_ADDRESS(), CONTRACT_ADDR, ByteUtil.EMPTY_BYTE_ARRAY), + context( + AionAddress.ZERO_ADDRESS(), + CONTRACT_ADDR, + ByteUtil.EMPTY_BYTE_ARRAY), this.repository, OWNER_ADDR, CONTRACT_ADDR); @@ -2562,7 +2583,7 @@ public void testSetReplayer() { assertThat(result.getResultCode()).isEqualTo(PrecompiledResultCode.SUCCESS); // caller not owner - fail - AionAddress address1 = AionAddress.wrap(ECKeyFac.inst().create().getAddress()); + Address address1 = AionAddress.wrap(ECKeyFac.inst().create().getAddress()); this.contract = new TokenBridgeContract( context(address1, CONTRACT_ADDR, ByteUtil.EMPTY_BYTE_ARRAY), @@ -2587,7 +2608,10 @@ public void testFallbackTransaction() { // override defaults this.contract = new TokenBridgeContract( - context(AionAddress.ZERO_ADDRESS(), CONTRACT_ADDR, ByteUtil.EMPTY_BYTE_ARRAY), + context( + AionAddress.ZERO_ADDRESS(), + CONTRACT_ADDR, + ByteUtil.EMPTY_BYTE_ARRAY), this.repository, OWNER_ADDR, CONTRACT_ADDR); @@ -2595,7 +2619,8 @@ public void testFallbackTransaction() { this.connector = this.contract.getConnector(); assertThat(this.connector.getInitialized()).isFalse(); - PrecompiledTransactionResult result = this.contract.execute(ByteUtil.EMPTY_BYTE_ARRAY, 21_000L); + PrecompiledTransactionResult result = + this.contract.execute(ByteUtil.EMPTY_BYTE_ARRAY, 21_000L); assertThat(result.getResultCode()).isEqualTo(PrecompiledResultCode.SUCCESS); assertThat(this.connector.getInitialized()).isTrue(); } diff --git a/modPrecompiled/test/org/aion/precompiled/contracts/AionAuctionContractTest.java b/modPrecompiled/test/org/aion/precompiled/contracts/AionAuctionContractTest.java index 096c961231..269016c223 100644 --- a/modPrecompiled/test/org/aion/precompiled/contracts/AionAuctionContractTest.java +++ b/modPrecompiled/test/org/aion/precompiled/contracts/AionAuctionContractTest.java @@ -18,6 +18,7 @@ import org.aion.mcf.db.IBlockStoreBase; import org.aion.precompiled.PrecompiledResultCode; import org.aion.precompiled.PrecompiledTransactionResult; +import org.aion.vm.api.interfaces.Address; import org.aion.zero.impl.StandaloneBlockchain; import org.aion.zero.impl.types.AionBlock; import org.aion.zero.types.AionTransaction; @@ -31,9 +32,9 @@ @Ignore public class AionAuctionContractTest { // use this addr for test to trigger test time periods - private static final AionAddress AION = + private static final Address AION = AionAddress.wrap("0xa0eeaeabdbc92953b072afbd21f3e3fd8a4a4f5e6a6e22200db746ab75e9a99a"); - private AionAddress domainAddress1 = + private Address domainAddress1 = AionAddress.wrap("a011111111111111111111111111111101010101010101010101010101010101"); private String domainName1 = "bion.aion"; private String domainName2 = "cion.aion.aion"; @@ -806,8 +807,7 @@ public void testRequestInactiveDomain() { assertEquals(32, result2.getOutput().length); // check that an address was returned } - private byte[] setupInputs( - String domainName, AionAddress ownerAddress, byte[] amount, ECKey k) { + private byte[] setupInputs(String domainName, Address ownerAddress, byte[] amount, ECKey k) { int domainLength = domainName.length(); int amountLength = amount.length; int offset = 0; @@ -830,7 +830,7 @@ private byte[] setupInputs( return ret; } - private byte[] setupForExtension(String domainName, AionAddress ownerAddress) { + private byte[] setupForExtension(String domainName, Address ownerAddress) { int domainLength = domainName.length(); int offset = 0; byte[] ret = new byte[1 + domainLength + 32 + 96 + 1]; @@ -882,7 +882,7 @@ private static AionBlock createBundleAndCheck( // create 100 transactions per bundle for (int i = 0; i < 100; i++) { - AionAddress destAddr = new AionAddress(HashUtil.h256(accountNonce.toByteArray())); + Address destAddr = new AionAddress(HashUtil.h256(accountNonce.toByteArray())); AionTransaction sendTransaction = new AionTransaction( accountNonce.toByteArray(), diff --git a/modPrecompiled/test/org/aion/precompiled/contracts/AionNameServiceContractTest.java b/modPrecompiled/test/org/aion/precompiled/contracts/AionNameServiceContractTest.java index 63259b7c81..8272c2fa2f 100644 --- a/modPrecompiled/test/org/aion/precompiled/contracts/AionNameServiceContractTest.java +++ b/modPrecompiled/test/org/aion/precompiled/contracts/AionNameServiceContractTest.java @@ -24,6 +24,7 @@ import org.aion.mcf.vm.types.DataWord; import org.aion.precompiled.PrecompiledResultCode; import org.aion.precompiled.PrecompiledTransactionResult; +import org.aion.vm.api.interfaces.Address; import org.aion.zero.impl.StandaloneBlockchain; import org.aion.zero.impl.types.AionBlock; import org.aion.zero.types.AionTransaction; @@ -48,40 +49,40 @@ public class AionNameServiceContractTest { private String domainName6 = "aion.aion.aion"; // subdomain of domainName1 and domainName2 private String notSubdomain = "aion.bion"; // not a subdomain of domainName1 - private static final AionAddress AION = + private static final Address AION = AionAddress.wrap("0xa0eeaeabdbc92953b072afbd21f3e3fd8a4a4f5e6a6e22200db746ab75e9a99a"); - private AionAddress emptyAddress = + private Address emptyAddress = AionAddress.wrap("0000000000000000000000000000000000000000000000000000000000000000"); - private AionAddress domainAddress1 = + private Address domainAddress1 = AionAddress.wrap("a011111111111111111111111111111101010101010101010101010101010101"); - private AionAddress domainAddress2 = + private Address domainAddress2 = AionAddress.wrap("a022222222222222222222222222222202020202020202020202020202020202"); - private AionAddress domainAddress3 = + private Address domainAddress3 = AionAddress.wrap("a033333333333333333333333333333303030303030303030303030303030303"); - private AionAddress domainAddress4 = + private Address domainAddress4 = AionAddress.wrap("a044444444444444444444444444444404040404040404040404040404040404"); - private AionAddress domainAddress5 = + private Address domainAddress5 = AionAddress.wrap("a055555555555555555555555555555505050505050050505050505050505050"); - private AionAddress domainAddress6 = + private Address domainAddress6 = AionAddress.wrap("a066666666666666666666666666666606060606060606060606060606060060"); - private AionAddress invalidDomainAddress = + private Address invalidDomainAddress = AionAddress.wrap("b066666666666666666666666666666606060606060606060606060606060606"); - private AionAddress newAddress1 = + private Address newAddress1 = AionAddress.wrap("1000000000000000000000000000000000000000000000000000000000000001"); - private AionAddress newAddress2 = + private Address newAddress2 = AionAddress.wrap("0100000000000000000000000000000000000000000000000000000000000010"); - private AionAddress newAddress3 = + private Address newAddress3 = AionAddress.wrap("0010000000000000000000000000000000000000000000000000000000000100"); - private AionAddress newAddress4 = + private Address newAddress4 = AionAddress.wrap("0001000000000000000000000000000000000000000000000000000000001000"); - private AionAddress newAddress5 = + private Address newAddress5 = AionAddress.wrap("0000100000000000000000000000000000000000000000000000000000010000"); - private AionAddress newAddress6 = + private Address newAddress6 = AionAddress.wrap("0000010000000000000000000000000000000000000000000000000000100000"); - private AionAddress newAddress7 = + private Address newAddress7 = AionAddress.wrap("0000001000000000000000000000000000000000000000000000000001000000"); - private AionAddress newAddress8 = + private Address newAddress8 = AionAddress.wrap("0000000100000000000000000000000000000000000000000000000010000000"); private IRepositoryCache> repo; @@ -92,8 +93,8 @@ public class AionNameServiceContractTest { private ECKey k3; private ECKey k4; private ECKey k5; - private AionAddress defaultAddress; - private AionAddress defaultAddress2; + private Address defaultAddress; + private Address defaultAddress2; private long DEFAULT_INPUT_NRG = 24000; static IBlockchain blockchain; @@ -332,7 +333,7 @@ public void testSetResolver() { // execute ANS contract PrecompiledTransactionResult res = ansc.execute(combined, inputEnergy); - AionAddress actualReturnedAddress = ansc.getResolverAddress(); + Address actualReturnedAddress = ansc.getResolverAddress(); // check for success and failure assertEquals(PrecompiledResultCode.SUCCESS, res.getResultCode()); @@ -362,7 +363,7 @@ public void testSetTTL() { // execute ANS contract PrecompiledTransactionResult res = ansc.execute(combined, inputEnergy); - AionAddress actualReturnedAddress = ansc.getTTL(); + Address actualReturnedAddress = ansc.getTTL(); // check for success and failure assertEquals(PrecompiledResultCode.SUCCESS, res.getResultCode()); @@ -421,7 +422,7 @@ public void incorrectInputLength() { // execute ANS contract PrecompiledTransactionResult res = ansc.execute(wrongLength, inputEnergy); - AionAddress actualReturnedAddress = ansc.getResolverAddress(); + Address actualReturnedAddress = ansc.getResolverAddress(); // check for success and failure assertEquals(PrecompiledResultCode.FAILURE, res.getResultCode()); @@ -457,7 +458,7 @@ public void testIncorrectSignature() { // execute ANS contract PrecompiledTransactionResult res = ansc.execute(combined, inputEnergy); - AionAddress actualReturnedAddress = ansc.getResolverAddress(); + Address actualReturnedAddress = ansc.getResolverAddress(); // check for success and failure assertEquals(PrecompiledResultCode.FAILURE, res.getResultCode()); @@ -487,7 +488,7 @@ public void testUnsupportedOperation() { // execute ANS contract PrecompiledTransactionResult res = ansc.execute(combined, inputEnergy); - AionAddress actualReturnedAddress = ansc.getResolverAddress(); + Address actualReturnedAddress = ansc.getResolverAddress(); // check for success and failure assertEquals(PrecompiledResultCode.FAILURE, res.getResultCode()); @@ -522,7 +523,7 @@ public void testIncorrectPublicKey() { // execute ANS contract PrecompiledTransactionResult res = ansc.execute(combined, inputEnergy); - AionAddress actualReturnedAddress = ansc.getResolverAddress(); + Address actualReturnedAddress = ansc.getResolverAddress(); // check for success and failure assertEquals(PrecompiledResultCode.FAILURE, res.getResultCode()); @@ -561,9 +562,9 @@ public void testTransferOwnership() { // execute ANS contract PrecompiledTransactionResult res = ansc.execute(combined, inputEnergy); - AionAddress actualReturnedAddress = ansc.getOwnerAddress(); + Address actualReturnedAddress = ansc.getOwnerAddress(); PrecompiledTransactionResult res2 = ansc.execute(combined2, inputEnergy); - AionAddress actualReturnedAddress2 = ansc.getOwnerAddress(); + Address actualReturnedAddress2 = ansc.getOwnerAddress(); // check for success and failure for execute with valid new address assertEquals(PrecompiledResultCode.SUCCESS, res.getResultCode()); @@ -626,9 +627,9 @@ public void testInsufficientEnergy() { PrecompiledTransactionResult res3 = ansc.execute(combined3, inputEnergy); PrecompiledTransactionResult res4 = ansc.execute(combined4, inputEnergy); - AionAddress actualReturnedAddress = ansc.getResolverAddress(); - AionAddress actualReturnedAddress2 = ansc.getTTL(); - AionAddress actualReturnedAddress3 = ansc.getOwnerAddress(); + Address actualReturnedAddress = ansc.getResolverAddress(); + Address actualReturnedAddress2 = ansc.getTTL(); + Address actualReturnedAddress3 = ansc.getOwnerAddress(); // check for success and failure assertEquals(PrecompiledResultCode.OUT_OF_NRG, res.getResultCode()); @@ -730,7 +731,7 @@ public void testANSQuery() { k); AionAuctionContract aac = new AionAuctionContract(repo, AION, blockchain); PrecompiledTransactionResult result = aac.execute(combined, DEFAULT_INPUT_NRG); - AionAddress addr = AionAddress.wrap(result.getOutput()); + Address addr = AionAddress.wrap(result.getOutput()); byte[] combined2 = setupInputs( @@ -800,7 +801,7 @@ public void testANSQuery() { /** Helper functions for setup, conversion, and storage */ // for ans basic operation private byte[] setupInputs( - AionAddress ownerAddress, AionAddress newAddress, byte id, byte operation, ECKey k) { + Address ownerAddress, Address newAddress, byte id, byte operation, ECKey k) { ByteBuffer bb = ByteBuffer.allocate(34); bb.put(id) // chainID .put(operation) // OPERATION HERE @@ -817,11 +818,11 @@ private byte[] setupInputs( // for ans subdomain operation private byte[] setupInputs( - AionAddress newAddress, + Address newAddress, byte id, byte operation, ECKey k, - AionAddress subdomainAddress, + Address subdomainAddress, String domainName, String subdomainName) { ByteBuffer bb = ByteBuffer.allocate(34); @@ -854,12 +855,12 @@ private byte[] setupInputs( // for auction setup private byte[] setupInputs( - AionAddress ownerAddress, - AionAddress newAddress, + Address ownerAddress, + Address newAddress, byte id, byte operation, ECKey k, - AionAddress subdomainAddress, + Address subdomainAddress, String domainName, String subdomainName) { ByteBuffer bb = ByteBuffer.allocate(34); @@ -916,11 +917,7 @@ private DummyRepo populateRepo() { } private void storeValueToRepo( - DummyRepo repo, - AionAddress domainAddress, - byte[] hash1, - byte[] hash2, - AionAddress value) { + DummyRepo repo, Address domainAddress, byte[] hash1, byte[] hash2, Address value) { byte[] combined = value.toBytes(); byte[] value1 = new byte[16]; byte[] value2 = new byte[16]; @@ -931,7 +928,7 @@ private void storeValueToRepo( private void storeValueToRepo( DummyRepo repo, - AionAddress domainAddress, + Address domainAddress, byte[] hash1, byte[] hash2, byte[] value1, @@ -946,8 +943,7 @@ private void createAccounts(DummyRepo repository, ECKey[] accountList) { for (ECKey key : accountList) repository.createAccount(AionAddress.wrap(key.getAddress())); } - private byte[] setupInputs( - String domainName, AionAddress ownerAddress, byte[] amount, ECKey k) { + private byte[] setupInputs(String domainName, Address ownerAddress, byte[] amount, ECKey k) { int domainLength = domainName.length(); int amountLength = amount.length; int offset = 0; @@ -1002,7 +998,7 @@ private static AionBlock createBundleAndCheck( // create 100 transactions per bundle for (int i = 0; i < 100; i++) { - AionAddress destAddr = new AionAddress(HashUtil.h256(accountNonce.toByteArray())); + Address destAddr = new AionAddress(HashUtil.h256(accountNonce.toByteArray())); AionTransaction sendTransaction = new AionTransaction( accountNonce.toByteArray(), diff --git a/modPrecompiled/test/org/aion/precompiled/contracts/BenchmarkTest.java b/modPrecompiled/test/org/aion/precompiled/contracts/BenchmarkTest.java index 897f1142ce..af79f2be07 100644 --- a/modPrecompiled/test/org/aion/precompiled/contracts/BenchmarkTest.java +++ b/modPrecompiled/test/org/aion/precompiled/contracts/BenchmarkTest.java @@ -10,6 +10,7 @@ import org.aion.mcf.vm.types.DataWord; import org.aion.precompiled.ContractFactory; import org.aion.precompiled.type.PrecompiledContract; +import org.aion.vm.api.interfaces.Address; import org.aion.zero.impl.config.CfgAion; import org.apache.commons.lang3.RandomUtils; import org.junit.After; @@ -22,7 +23,7 @@ public class BenchmarkTest { private ExecutionContext ctx; private byte[] txHash, callData; - private AionAddress origin, caller, blockCoinbase; + private Address origin, caller, blockCoinbase; private long blockNumber, blockTimestamp, blockNrgLimit, nrgLimit; private DataWord blockDifficulty, nrgPrice, callValue; private int depth, kind, flags; diff --git a/modPrecompiled/test/org/aion/precompiled/contracts/DummyRepo.java b/modPrecompiled/test/org/aion/precompiled/contracts/DummyRepo.java index 252b10eb68..d9f96d0da7 100644 --- a/modPrecompiled/test/org/aion/precompiled/contracts/DummyRepo.java +++ b/modPrecompiled/test/org/aion/precompiled/contracts/DummyRepo.java @@ -9,7 +9,6 @@ import org.aion.base.db.IContractDetails; import org.aion.base.db.IRepository; import org.aion.base.db.IRepositoryCache; -import org.aion.base.type.AionAddress; import org.aion.base.util.ByteArrayWrapper; import org.aion.base.util.ByteUtil; import org.aion.mcf.core.AccountState; @@ -37,7 +36,7 @@ public DummyRepo(DummyRepo parent) { storage.putAll(parent.storage); } - void addContract(AionAddress address, byte[] code) { + void addContract(Address address, byte[] code) { contracts.put(address, code); } diff --git a/modPrecompiled/test/org/aion/precompiled/contracts/EDVerifyContractTest.java b/modPrecompiled/test/org/aion/precompiled/contracts/EDVerifyContractTest.java index 677638a9a8..a37a1107f6 100644 --- a/modPrecompiled/test/org/aion/precompiled/contracts/EDVerifyContractTest.java +++ b/modPrecompiled/test/org/aion/precompiled/contracts/EDVerifyContractTest.java @@ -22,6 +22,7 @@ import org.aion.precompiled.ContractFactory; import org.aion.precompiled.PrecompiledResultCode; import org.aion.precompiled.type.PrecompiledContract; +import org.aion.vm.api.interfaces.Address; import org.aion.vm.api.interfaces.TransactionResult; import org.aion.zero.impl.config.CfgAion; import org.apache.commons.lang3.RandomUtils; @@ -33,10 +34,10 @@ public class EDVerifyContractTest { private byte[] txHash = RandomUtils.nextBytes(32); - private AionAddress origin = AionAddress.wrap(RandomUtils.nextBytes(32)); - private AionAddress caller = origin; + private Address origin = AionAddress.wrap(RandomUtils.nextBytes(32)); + private Address caller = origin; - private AionAddress blockCoinbase = AionAddress.wrap(RandomUtils.nextBytes(32)); + private Address blockCoinbase = AionAddress.wrap(RandomUtils.nextBytes(32)); private long blockNumber = 2000001; private long blockTimestamp = System.currentTimeMillis() / 1000; private long blockNrgLimit = 5000000; diff --git a/modPrecompiled/test/org/aion/precompiled/contracts/MultiSignatureContractTest.java b/modPrecompiled/test/org/aion/precompiled/contracts/MultiSignatureContractTest.java index c615698d87..a82586ee85 100644 --- a/modPrecompiled/test/org/aion/precompiled/contracts/MultiSignatureContractTest.java +++ b/modPrecompiled/test/org/aion/precompiled/contracts/MultiSignatureContractTest.java @@ -23,6 +23,7 @@ import org.aion.precompiled.PrecompiledResultCode; import org.aion.precompiled.PrecompiledTransactionResult; import org.aion.precompiled.type.StatefulPrecompiledContract; +import org.aion.vm.api.interfaces.Address; import org.junit.After; import org.junit.Before; import org.junit.Ignore; @@ -38,9 +39,9 @@ public class MultiSignatureContractTest { private static final BigInteger AMOUNT = BigInteger.TEN; private static final long NRG_LIMIT = 100000L; private static final long NRG_PRICE = 10000000000L; - private AionAddress to; + private Address to; private IRepositoryCache repo; - private List addrsToClean; + private List
addrsToClean; @Before public void setup() { @@ -52,7 +53,7 @@ public void setup() { @After public void tearDown() { - for (AionAddress addr : addrsToClean) { + for (Address addr : addrsToClean) { repo.deleteAccount(addr); } repo = null; @@ -65,7 +66,7 @@ public void tearDown() { // Executes a MSC with input and NRG_LIMIT args, calls it with address caller, and expects // code and nrg as results of the execution. Returns the result. private PrecompiledTransactionResult execute( - AionAddress caller, byte[] input, long nrgLimit, PrecompiledResultCode code, long nrg) { + Address caller, byte[] input, long nrgLimit, PrecompiledResultCode code, long nrg) { MultiSignatureContract msc = new MultiSignatureContract(repo, caller); PrecompiledTransactionResult res = msc.execute(input, nrgLimit); @@ -75,8 +76,8 @@ private PrecompiledTransactionResult execute( } // Creates a new account with initial balance balance that will be deleted at test end. - private AionAddress getExistentAddress(BigInteger balance) { - AionAddress addr = AionAddress.wrap(ECKeyFac.inst().create().getAddress()); + private Address getExistentAddress(BigInteger balance) { + Address addr = AionAddress.wrap(ECKeyFac.inst().create().getAddress()); repo.createAccount(addr); repo.addBalance(addr, balance); addrsToClean.add(addr); @@ -84,8 +85,8 @@ private AionAddress getExistentAddress(BigInteger balance) { } // Returns a list of existent accounts of size numOwners, each of which has initial balance. - private List getExistentAddresses(long numOwners, BigInteger balance) { - List accounts = new ArrayList<>(); + private List
getExistentAddresses(long numOwners, BigInteger balance) { + List
accounts = new ArrayList<>(); for (int i = 0; i < numOwners; i++) { accounts.add(getExistentAddress(balance)); } @@ -94,9 +95,9 @@ private List getExistentAddresses(long numOwners, BigInteger balanc // Returns a list of existent accounts of size umOtherOwners + 1 that contains owner and then // numOtherOwners other owners each with initial balance balance. - private List getExistentAddresses( - long numOtherOwners, AionAddress owner, BigInteger balance) { - List accounts = new ArrayList<>(); + private List
getExistentAddresses( + long numOtherOwners, Address owner, BigInteger balance) { + List
accounts = new ArrayList<>(); for (int i = 0; i < numOtherOwners; i++) { accounts.add(getExistentAddress(balance)); } @@ -108,8 +109,8 @@ private List getExistentAddresses( private static byte[] customMsg( IRepositoryCache repo, BigInteger nonce, - AionAddress walletId, - AionAddress to, + Address walletId, + Address to, BigInteger amount, long nrgPrice, long nrgLimit) { @@ -134,16 +135,12 @@ private static byte[] customMsg( // Returns a properly formatted byte array for these input params for send-tx logic. We want to // allow null values so we can simulate missing elements in the input array. private byte[] toValidSendInput( - AionAddress wallet, - List signatures, - BigInteger amount, - long nrg, - AionAddress to) { + Address wallet, List signatures, BigInteger amount, long nrg, Address to) { - int walletLen = (wallet == null) ? 0 : AionAddress.SIZE; + int walletLen = (wallet == null) ? 0 : Address.SIZE; int sigsLen = (signatures == null) ? 0 : (signatures.size() * SIG_SIZE); int amtLen = (amount == null) ? 0 : AMT_SIZE; - int toLen = (to == null) ? 0 : AionAddress.SIZE; + int toLen = (to == null) ? 0 : Address.SIZE; int len = 1 + walletLen + sigsLen + amtLen + Long.BYTES + toLen; byte[] input = new byte[len]; @@ -152,8 +149,8 @@ private byte[] toValidSendInput( input[index] = (byte) 0x1; index++; if (wallet != null) { - System.arraycopy(wallet.toBytes(), 0, input, index, AionAddress.SIZE); - index += AionAddress.SIZE; + System.arraycopy(wallet.toBytes(), 0, input, index, Address.SIZE); + index += Address.SIZE; } if (signatures != null) { @@ -181,7 +178,7 @@ private byte[] toValidSendInput( index += Long.BYTES; if (to != null) { - System.arraycopy(to.toBytes(), 0, input, index, AionAddress.SIZE); + System.arraycopy(to.toBytes(), 0, input, index, Address.SIZE); } return input; } @@ -189,7 +186,7 @@ private byte[] toValidSendInput( // Returns a list of size 2 containing the threshold & number of owners of this multi-sig // wallet. // If walletId is not a multi-sig wallet this method fails. - private List getWalletThresholdAndNumOwners(AionAddress walletId) { + private List getWalletThresholdAndNumOwners(Address walletId) { List values = new ArrayList<>(); byte[] metaKey = new byte[DataWord.BYTES]; metaKey[0] = (byte) 0x80; @@ -212,13 +209,13 @@ private List getWalletThresholdAndNumOwners(AionAddress walletId) { // Returns a set of numOwners owners of the wallet. If the wallet has duplicate owners this // method fails. - private Set getWalletOwners(AionAddress walletId, long numOwners) { - Set owners = new HashSet<>(); + private Set
getWalletOwners(Address walletId, long numOwners) { + Set
owners = new HashSet<>(); ByteBuffer buffer = ByteBuffer.allocate(Long.BYTES); ByteArrayWrapper portion; for (long i = 0; i < numOwners; i++) { - byte[] account = new byte[AionAddress.SIZE]; + byte[] account = new byte[Address.SIZE]; buffer.putLong(i); buffer.flip(); byte[] request = new byte[DataWord.BYTES]; @@ -236,7 +233,7 @@ private Set getWalletOwners(AionAddress walletId, long numOwners) { } System.arraycopy(portion.getData(), 0, account, DataWord.BYTES, DataWord.BYTES); - AionAddress address = new AionAddress(account); + Address address = new AionAddress(account); if (owners.contains(address)) { fail(); } @@ -258,13 +255,13 @@ private List produceKeys(long numKeys) { // Returns the address of the new multi-sig wallet that uses the addresses in the keys of owners // as the owners, requires at least threshold signatures and has initial balance balance. - private AionAddress createMultiSigWallet( + private Address createMultiSigWallet( List owners, long threshold, BigInteger balance) { if (owners.isEmpty()) { fail(); } - List ownerAddrs = new ArrayList<>(); - AionAddress addr; + List
ownerAddrs = new ArrayList<>(); + Address addr; for (ECKeyEd25519 key : owners) { addr = new AionAddress(key.getAddress()); repo.createAccount(addr); @@ -276,7 +273,7 @@ private AionAddress createMultiSigWallet( MultiSignatureContract msc = new MultiSignatureContract(repo, ownerAddrs.get(0)); PrecompiledTransactionResult res = msc.execute(input, COST); assertEquals(PrecompiledResultCode.SUCCESS, res.getResultCode()); - AionAddress wallet = new AionAddress(res.getOutput()); + Address wallet = new AionAddress(res.getOutput()); repo.addBalance(wallet, balance); addrsToClean.add(wallet); repo.flush(); @@ -303,8 +300,8 @@ private List produceSignatures(List owners, int numSig // Verifies that the result of a create-wallet operation, res, saves a wallet with threshold // threshold and consists of all the owners in owners and no more. private void checkCreateResult( - PrecompiledTransactionResult res, long threshold, List owners) { - AionAddress walletId = new AionAddress(res.getOutput()); + PrecompiledTransactionResult res, long threshold, List
owners) { + Address walletId = new AionAddress(res.getOutput()); addrsToClean.add(walletId); assertEquals(BigInteger.ZERO, repo.getBalance(walletId)); assertEquals(BigInteger.ZERO, repo.getNonce(walletId)); @@ -313,15 +310,15 @@ private void checkCreateResult( assertEquals(threshold, threshAndOwners.get(0).longValue()); assertEquals(owners.size(), threshAndOwners.get(1).longValue()); - Set walletOwners = getWalletOwners(walletId, threshAndOwners.get(1)); + Set
walletOwners = getWalletOwners(walletId, threshAndOwners.get(1)); assertEquals(owners.size(), walletOwners.size()); - for (AionAddress own : owners) { + for (Address own : owners) { assertTrue(walletOwners.contains(own)); } } // Verifies that account has a nonce equal to nonce and a balance equal to balance. - private void checkAccountState(AionAddress account, BigInteger nonce, BigInteger balance) { + private void checkAccountState(Address account, BigInteger nonce, BigInteger balance) { assertEquals(nonce, repo.getNonce(account)); assertEquals(balance, repo.getBalance(account)); } @@ -342,8 +339,8 @@ public void testConstructWithNullCaller() { public void testNrgBelowLegalLimit() { // First test create-wallet logic. // Test with min illegal cost. - AionAddress caller = getExistentAddress(BigInteger.ZERO); - List owners = getExistentAddresses(3, BigInteger.ZERO); + Address caller = getExistentAddress(BigInteger.ZERO); + List
owners = getExistentAddresses(3, BigInteger.ZERO); byte[] input = MultiSignatureContract.constructCreateWalletInput( MultiSignatureContract.MIN_THRESH, owners); @@ -356,8 +353,8 @@ public void testNrgBelowLegalLimit() { // Second test send-tx logic. // Test with min illegal cost. List sendOwners = produceKeys(MultiSignatureContract.MIN_OWNERS); - AionAddress sendCaller = new AionAddress(sendOwners.get(0).getAddress()); - AionAddress wallet = + Address sendCaller = new AionAddress(sendOwners.get(0).getAddress()); + Address wallet = createMultiSigWallet( sendOwners, MultiSignatureContract.MIN_OWNERS - 1, DEFAULT_BALANCE); byte[] txMsg = @@ -393,8 +390,8 @@ public void testNrgAboveThanCost() { // First test create-wallet logic. // Test with min illegal cost. - AionAddress caller = getExistentAddress(BigInteger.ZERO); - List owners = getExistentAddresses(3, BigInteger.ZERO); + Address caller = getExistentAddress(BigInteger.ZERO); + List
owners = getExistentAddresses(3, BigInteger.ZERO); byte[] input = MultiSignatureContract.constructCreateWalletInput( MultiSignatureContract.MIN_THRESH, owners); @@ -402,13 +399,18 @@ public void testNrgAboveThanCost() { execute(caller, input, nrgLimit, PrecompiledResultCode.INVALID_NRG_LIMIT, nrgLimit); // Test with max illegal cost. - execute(caller, input, Long.MAX_VALUE, PrecompiledResultCode.INVALID_NRG_LIMIT, Long.MAX_VALUE); + execute( + caller, + input, + Long.MAX_VALUE, + PrecompiledResultCode.INVALID_NRG_LIMIT, + Long.MAX_VALUE); // Second test send-tx logic. // Test with min illegal cost. List sendOwners = produceKeys(MultiSignatureContract.MIN_OWNERS); - AionAddress sendCaller = new AionAddress(sendOwners.get(0).getAddress()); - AionAddress wallet = + Address sendCaller = new AionAddress(sendOwners.get(0).getAddress()); + Address wallet = createMultiSigWallet( sendOwners, MultiSignatureContract.MIN_OWNERS - 1, DEFAULT_BALANCE); byte[] txMsg = @@ -441,27 +443,27 @@ public void testNrgAboveThanCost() { @Test public void testNullInput() { - AionAddress caller = getExistentAddress(BigInteger.ZERO); + Address caller = getExistentAddress(BigInteger.ZERO); execute(caller, null, COST, PrecompiledResultCode.FAILURE, 0); } @Test public void testEmptyInput() { - AionAddress caller = getExistentAddress(BigInteger.ZERO); + Address caller = getExistentAddress(BigInteger.ZERO); execute(caller, ByteUtil.EMPTY_BYTE_ARRAY, COST, PrecompiledResultCode.FAILURE, 0); } @Test public void testInputWithOperationOnly() { - AionAddress caller = getExistentAddress(BigInteger.ZERO); + Address caller = getExistentAddress(BigInteger.ZERO); execute(caller, new byte[] {(byte) 0x0}, COST, PrecompiledResultCode.FAILURE, 0); execute(caller, new byte[] {(byte) 0x1}, COST, PrecompiledResultCode.FAILURE, 0); } @Test public void testInputWithUnsupportedOperation() { - AionAddress caller = getExistentAddress(BigInteger.ZERO); - List owners = getExistentAddresses(3, BigInteger.ZERO); + Address caller = getExistentAddress(BigInteger.ZERO); + List
owners = getExistentAddresses(3, BigInteger.ZERO); byte[] input = MultiSignatureContract.constructCreateWalletInput( MultiSignatureContract.MIN_THRESH, owners); @@ -480,8 +482,8 @@ public void testInputWithUnsupportedOperation() { @Test public void testCreateWalletThresholdBelowLegalLimit() { // Test with min illegal value. - List owners = getExistentAddresses(3, BigInteger.ZERO); - AionAddress caller = owners.get(0); + List
owners = getExistentAddresses(3, BigInteger.ZERO); + Address caller = owners.get(0); byte[] input = MultiSignatureContract.constructCreateWalletInput(Long.MIN_VALUE, owners); execute(caller, input, COST, PrecompiledResultCode.FAILURE, 0); @@ -496,8 +498,8 @@ public void testCreateWalletThresholdBelowLegalLimit() { @Test public void testCreateWalletWithThresholdLargerThanNumOwners() { // Test with max illegal value. - List owners = getExistentAddresses(3, BigInteger.ZERO); - AionAddress caller = owners.get(0); + List
owners = getExistentAddresses(3, BigInteger.ZERO); + Address caller = owners.get(0); byte[] input = MultiSignatureContract.constructCreateWalletInput(Long.MAX_VALUE, owners); execute(caller, input, COST, PrecompiledResultCode.FAILURE, 0); @@ -509,8 +511,8 @@ public void testCreateWalletWithThresholdLargerThanNumOwners() { @Test public void testCreateWalletZeroOwners() { - AionAddress caller = getExistentAddress(BigInteger.ZERO); - List owners = new ArrayList<>(); + Address caller = getExistentAddress(BigInteger.ZERO); + List
owners = new ArrayList<>(); byte[] input = MultiSignatureContract.constructCreateWalletInput( MultiSignatureContract.MIN_THRESH, owners); @@ -520,8 +522,8 @@ public void testCreateWalletZeroOwners() { @Test public void testCreateWalletOneOwner() { - AionAddress caller = getExistentAddress(BigInteger.ZERO); - List owners = getExistentAddresses(1, BigInteger.ZERO); + Address caller = getExistentAddress(BigInteger.ZERO); + List
owners = getExistentAddresses(1, BigInteger.ZERO); byte[] input = MultiSignatureContract.constructCreateWalletInput(Long.MAX_VALUE, owners); execute(caller, input, COST, PrecompiledResultCode.FAILURE, 0); @@ -529,9 +531,9 @@ public void testCreateWalletOneOwner() { @Test public void testCreateWalletWithMoreOwnersThanLegalLimit() { - List owners = + List
owners = getExistentAddresses(MultiSignatureContract.MAX_OWNERS + 1, BigInteger.ZERO); - AionAddress caller = owners.get(0); + Address caller = owners.get(0); byte[] input = MultiSignatureContract.constructCreateWalletInput(Long.MAX_VALUE, owners); execute(caller, input, COST, PrecompiledResultCode.FAILURE, 0); @@ -540,8 +542,8 @@ public void testCreateWalletWithMoreOwnersThanLegalLimit() { @Test public void testCreateWalletWithTwoDuplicateOwners() { // Test with max amount of owners - AionAddress caller = getExistentAddress(BigInteger.ZERO); - List owners = + Address caller = getExistentAddress(BigInteger.ZERO); + List
owners = getExistentAddresses(MultiSignatureContract.MAX_OWNERS - 1, BigInteger.ZERO); owners.add(owners.get(0)); byte[] input = @@ -573,8 +575,8 @@ public void testCreateWalletWithTwoDuplicateOwners() { @Test public void testCreateWalletButCallerIsNotAnOwner() { - AionAddress caller = getExistentAddress(BigInteger.ZERO); - List owners = + Address caller = getExistentAddress(BigInteger.ZERO); + List
owners = getExistentAddresses(MultiSignatureContract.MIN_OWNERS, BigInteger.ZERO); byte[] input = MultiSignatureContract.constructCreateWalletInput( @@ -586,15 +588,15 @@ public void testCreateWalletButCallerIsNotAnOwner() { @Test public void testCreateWalletWithPartiallyCompleteAddress() { // Test on nearly min legal number of owners. - AionAddress caller = getExistentAddress(BigInteger.ZERO); - List owners = + Address caller = getExistentAddress(BigInteger.ZERO); + List
owners = getExistentAddresses(MultiSignatureContract.MIN_OWNERS - 1, BigInteger.ZERO); owners.add(caller); byte[] in = MultiSignatureContract.constructCreateWalletInput( MultiSignatureContract.MIN_THRESH, owners); - byte[] partialAddr = new byte[AionAddress.SIZE - 1]; + byte[] partialAddr = new byte[Address.SIZE - 1]; ThreadLocalRandom.current().nextBytes(partialAddr); byte[] input = new byte[in.length + partialAddr.length]; @@ -619,8 +621,8 @@ public void testCreateWalletWithPartiallyCompleteAddress() { @Test public void testCreateWalletWithMultiSigWalletCaller() { // First create a multi-sig wallet. - AionAddress caller = getExistentAddress(BigInteger.ZERO); - List owners = + Address caller = getExistentAddress(BigInteger.ZERO); + List
owners = getExistentAddresses( MultiSignatureContract.MIN_OWNERS - 1, caller, BigInteger.ZERO); long threshold = owners.size(); @@ -629,7 +631,7 @@ public void testCreateWalletWithMultiSigWalletCaller() { PrecompiledTransactionResult res = execute(caller, input, NRG_LIMIT, PrecompiledResultCode.SUCCESS, NRG_LIMIT - COST); - AionAddress walletCaller = new AionAddress(res.getOutput()); + Address walletCaller = new AionAddress(res.getOutput()); addrsToClean.add(walletCaller); checkAccountState(walletCaller, BigInteger.ZERO, BigInteger.ZERO); @@ -647,8 +649,8 @@ public void testCreateWalletWithMultiSigWalletCaller() { @Test public void testCreateWalletWithOwnerAsAMultiSigWallet() { // First create a multi-sig wallet. - AionAddress caller = getExistentAddress(BigInteger.ZERO); - List owners = + Address caller = getExistentAddress(BigInteger.ZERO); + List
owners = getExistentAddresses( MultiSignatureContract.MIN_OWNERS - 1, caller, BigInteger.ZERO); long threshold = owners.size(); @@ -657,12 +659,12 @@ public void testCreateWalletWithOwnerAsAMultiSigWallet() { PrecompiledTransactionResult res = execute(caller, input, NRG_LIMIT, PrecompiledResultCode.SUCCESS, NRG_LIMIT - COST); - AionAddress wallet = new AionAddress(res.getOutput()); + Address wallet = new AionAddress(res.getOutput()); addrsToClean.add(wallet); checkAccountState(wallet, BigInteger.ZERO, BigInteger.ZERO); // Now try to create a wallet using this wallet as one of the owners. - AionAddress newCaller = getExistentAddress(BigInteger.ZERO); + Address newCaller = getExistentAddress(BigInteger.ZERO); owners = getExistentAddresses( MultiSignatureContract.MAX_OWNERS - 2, wallet, BigInteger.ZERO); @@ -677,8 +679,8 @@ public void testCreateWalletWithOwnerAsAMultiSigWallet() { @Test public void testCreateWalletWithThresholdEqualToLegalNumOwners() { // Test using min legal number of owners. - AionAddress caller = getExistentAddress(BigInteger.ZERO); - List owners = + Address caller = getExistentAddress(BigInteger.ZERO); + List
owners = getExistentAddresses( MultiSignatureContract.MIN_OWNERS - 1, caller, BigInteger.ZERO); long threshold = owners.size(); @@ -703,8 +705,8 @@ public void testCreateWalletWithThresholdEqualToLegalNumOwners() { @Test public void testCreateWalletAddressIsDeterministic() { - AionAddress caller = getExistentAddress(BigInteger.ZERO); - List owners = + Address caller = getExistentAddress(BigInteger.ZERO); + List
owners = getExistentAddresses( MultiSignatureContract.MIN_OWNERS - 1, caller, BigInteger.ZERO); long threshold = owners.size(); @@ -712,18 +714,18 @@ public void testCreateWalletAddressIsDeterministic() { PrecompiledTransactionResult res = execute(caller, input, NRG_LIMIT, PrecompiledResultCode.SUCCESS, NRG_LIMIT - COST); - AionAddress wallet1 = new AionAddress(res.getOutput()); + Address wallet1 = new AionAddress(res.getOutput()); res = execute(caller, input, NRG_LIMIT, PrecompiledResultCode.SUCCESS, NRG_LIMIT - COST); - AionAddress wallet2 = new AionAddress(res.getOutput()); + Address wallet2 = new AionAddress(res.getOutput()); assertEquals(wallet1, wallet2); } @Test public void testWalletAddressStartsWithAionPrefix() { - AionAddress caller = getExistentAddress(BigInteger.ZERO); - List owners = + Address caller = getExistentAddress(BigInteger.ZERO); + List
owners = getExistentAddresses( MultiSignatureContract.MIN_OWNERS - 1, caller, BigInteger.ZERO); long threshold = owners.size(); @@ -731,15 +733,15 @@ public void testWalletAddressStartsWithAionPrefix() { PrecompiledTransactionResult res = execute(caller, input, NRG_LIMIT, PrecompiledResultCode.SUCCESS, NRG_LIMIT - COST); - AionAddress wallet = new AionAddress(res.getOutput()); + Address wallet = new AionAddress(res.getOutput()); assertTrue(wallet.toString().startsWith("a0")); } @Test public void testCreateWalletWithMinimumLegalThreshold() { // Test using min legal number of owners. - AionAddress caller = getExistentAddress(BigInteger.ZERO); - List owners = + Address caller = getExistentAddress(BigInteger.ZERO); + List
owners = getExistentAddresses( MultiSignatureContract.MIN_OWNERS - 1, caller, BigInteger.ZERO); long threshold = MultiSignatureContract.MIN_THRESH; @@ -767,8 +769,8 @@ public void testCreateWalletWithMinimumLegalThreshold() { @Test public void testSendTxWithZeroSignatures() { List owners = produceKeys(MultiSignatureContract.MIN_OWNERS); - AionAddress caller = new AionAddress(owners.get(0).getAddress()); - AionAddress wallet = + Address caller = new AionAddress(owners.get(0).getAddress()); + Address wallet = createMultiSigWallet(owners, MultiSignatureContract.MIN_THRESH, DEFAULT_BALANCE); // No signatures. @@ -789,8 +791,8 @@ public void testSendTxWithZeroSignatures() { public void testSendTxWithMoreThanMaxOwnersSignatures() { List owners = produceKeys(MultiSignatureContract.MAX_OWNERS + 1); ECKeyEd25519 extra = owners.remove(0); - AionAddress caller = new AionAddress(owners.get(0).getAddress()); - AionAddress wallet = + Address caller = new AionAddress(owners.get(0).getAddress()); + Address wallet = createMultiSigWallet(owners, MultiSignatureContract.MAX_OWNERS, DEFAULT_BALANCE); // Have all owners plus one extra sign the tx. @@ -815,8 +817,8 @@ public void testSendTxWithMoreThanMaxOwnersSignatures() { public void testSendTxValidSignaturesMeetsThresholdPlusPhonySig() { List owners = produceKeys(MultiSignatureContract.MIN_OWNERS + 1); ECKeyEd25519 phony = owners.remove(0); - AionAddress caller = new AionAddress(owners.get(0).getAddress()); - AionAddress wallet = + Address caller = new AionAddress(owners.get(0).getAddress()); + Address wallet = createMultiSigWallet(owners, MultiSignatureContract.MIN_OWNERS, DEFAULT_BALANCE); // Have all owners sign, meet threshold requirement, and attach a phony signaure. @@ -840,8 +842,8 @@ public void testSendTxValidSignaturesMeetsThresholdPlusPhonySig() { @Test public void testSendTxNegativeAmountWithZeroBalance() { List owners = produceKeys(MultiSignatureContract.MIN_OWNERS); - AionAddress caller = new AionAddress(owners.get(0).getAddress()); - AionAddress wallet = + Address caller = new AionAddress(owners.get(0).getAddress()); + Address wallet = createMultiSigWallet(owners, MultiSignatureContract.MIN_THRESH, BigInteger.ZERO); BigInteger amt = AMOUNT.negate(); @@ -863,8 +865,8 @@ public void testSendTxNegativeAmountWithZeroBalance() { @Test public void testSendTxNegativeAmountWithActualBalance() { List owners = produceKeys(MultiSignatureContract.MIN_OWNERS); - AionAddress caller = new AionAddress(owners.get(0).getAddress()); - AionAddress wallet = + Address caller = new AionAddress(owners.get(0).getAddress()); + Address wallet = createMultiSigWallet(owners, MultiSignatureContract.MIN_THRESH, DEFAULT_BALANCE); BigInteger amt = AMOUNT.negate(); @@ -887,7 +889,7 @@ public void testSendTxNegativeAmountWithActualBalance() { public void testSendTxFromRegularAddress() { // Our wallet is not a wallet... List phonies = produceKeys(MultiSignatureContract.MIN_OWNERS); - AionAddress phonyWallet = new AionAddress(phonies.get(0).getAddress()); + Address phonyWallet = new AionAddress(phonies.get(0).getAddress()); repo.addBalance(phonyWallet, DEFAULT_BALANCE); BigInteger amt = BigInteger.ONE; @@ -910,8 +912,8 @@ public void testSendTxFromRegularAddress() { @Test public void testSendTxNoSenderInInput() { List owners = produceKeys(MultiSignatureContract.MIN_OWNERS); - AionAddress caller = new AionAddress(owners.get(0).getAddress()); - AionAddress wallet = + Address caller = new AionAddress(owners.get(0).getAddress()); + Address wallet = createMultiSigWallet(owners, MultiSignatureContract.MIN_OWNERS, DEFAULT_BALANCE); byte[] txMsg = @@ -932,8 +934,8 @@ public void testSendTxNoSenderInInput() { @Test public void testSendTxNoRecipient() { List owners = produceKeys(MultiSignatureContract.MIN_OWNERS); - AionAddress caller = new AionAddress(owners.get(0).getAddress()); - AionAddress wallet = + Address caller = new AionAddress(owners.get(0).getAddress()); + Address wallet = createMultiSigWallet(owners, MultiSignatureContract.MIN_OWNERS, DEFAULT_BALANCE); byte[] txMsg = @@ -954,8 +956,8 @@ public void testSendTxNoRecipient() { @Test public void testSendTxNoAmount() { List owners = produceKeys(MultiSignatureContract.MIN_OWNERS); - AionAddress caller = new AionAddress(owners.get(0).getAddress()); - AionAddress wallet = + Address caller = new AionAddress(owners.get(0).getAddress()); + Address wallet = createMultiSigWallet(owners, MultiSignatureContract.MIN_OWNERS, DEFAULT_BALANCE); byte[] txMsg = @@ -976,8 +978,8 @@ public void testSendTxNoAmount() { @Test public void testSendTxNoNrgPrice() { List owners = produceKeys(MultiSignatureContract.MIN_OWNERS); - AionAddress caller = new AionAddress(owners.get(0).getAddress()); - AionAddress wallet = + Address caller = new AionAddress(owners.get(0).getAddress()); + Address wallet = createMultiSigWallet(owners, MultiSignatureContract.MIN_OWNERS, DEFAULT_BALANCE); byte[] txMsg = @@ -990,13 +992,13 @@ public void testSendTxNoNrgPrice() { MultiSignatureContract.constructSendTxInput( wallet, signatures, AMOUNT, NRG_PRICE, to); byte[] noNrgInput = new byte[input.length - Long.BYTES]; - System.arraycopy(input, 0, noNrgInput, 0, input.length - AionAddress.SIZE - Long.BYTES - 1); + System.arraycopy(input, 0, noNrgInput, 0, input.length - Address.SIZE - Long.BYTES - 1); System.arraycopy( input, - input.length - AionAddress.SIZE, + input.length - Address.SIZE, noNrgInput, - input.length - AionAddress.SIZE - Long.BYTES, - AionAddress.SIZE); + input.length - Address.SIZE - Long.BYTES, + Address.SIZE); checkAccountState(wallet, BigInteger.ZERO, DEFAULT_BALANCE); checkAccountState(to, BigInteger.ZERO, BigInteger.ZERO); @@ -1008,8 +1010,8 @@ public void testSendTxNoNrgPrice() { @Test public void testSendTxWithSignatureUsingPreviousNonce() { List owners = produceKeys(MultiSignatureContract.MIN_OWNERS); - AionAddress caller = new AionAddress(owners.get(0).getAddress()); - AionAddress wallet = + Address caller = new AionAddress(owners.get(0).getAddress()); + Address wallet = createMultiSigWallet(owners, MultiSignatureContract.MIN_OWNERS, DEFAULT_BALANCE); // We sign a tx msg that uses the previous nonce. @@ -1039,8 +1041,8 @@ public void testSendTxWithSignatureUsingPreviousNonce() { @Test public void testSendTxWhereSignedMessagesDifferInNonce() { List owners = produceKeys(MultiSignatureContract.MIN_OWNERS); - AionAddress caller = new AionAddress(owners.get(0).getAddress()); - AionAddress wallet = + Address caller = new AionAddress(owners.get(0).getAddress()); + Address wallet = createMultiSigWallet(owners, MultiSignatureContract.MIN_OWNERS, DEFAULT_BALANCE); // One signee signs tx with a different nonce than the others. The others sign correct tx. @@ -1074,8 +1076,8 @@ public void testSendTxWhereSignedMessagesDifferInNonce() { @Test public void testSendTxWhereSignedMessagesDifferInRecipient() { List owners = produceKeys(MultiSignatureContract.MIN_OWNERS); - AionAddress caller = new AionAddress(owners.get(0).getAddress()); - AionAddress wallet = + Address caller = new AionAddress(owners.get(0).getAddress()); + Address wallet = createMultiSigWallet(owners, MultiSignatureContract.MIN_OWNERS, DEFAULT_BALANCE); // One signee signs tx with a different recipient than the others. The others sign correct @@ -1104,8 +1106,8 @@ public void testSendTxWhereSignedMessagesDifferInRecipient() { @Test public void testSendTxWhereSignedMessagesDifferInAmount() { List owners = produceKeys(MultiSignatureContract.MIN_OWNERS); - AionAddress caller = new AionAddress(owners.get(0).getAddress()); - AionAddress wallet = + Address caller = new AionAddress(owners.get(0).getAddress()); + Address wallet = createMultiSigWallet(owners, MultiSignatureContract.MIN_OWNERS, DEFAULT_BALANCE); // One signee signs tx with a different amount than the others. The others sign correct tx. @@ -1137,8 +1139,8 @@ public void testSendTxWhereSignedMessagesDifferInAmount() { @Test public void testSendTxWhereSignedMessagesDifferInNrgPrice() { List owners = produceKeys(MultiSignatureContract.MIN_OWNERS); - AionAddress caller = new AionAddress(owners.get(0).getAddress()); - AionAddress wallet = + Address caller = new AionAddress(owners.get(0).getAddress()); + Address wallet = createMultiSigWallet(owners, MultiSignatureContract.MIN_OWNERS, DEFAULT_BALANCE); // One signee signs tx with a different nrg price than the others. The others sign correct @@ -1167,10 +1169,10 @@ public void testSendTxWhereSignedMessagesDifferInNrgPrice() { @Test public void testSendTxAllSignWrongRecipient() { List owners = produceKeys(MultiSignatureContract.MIN_OWNERS); - AionAddress caller = new AionAddress(owners.get(0).getAddress()); - AionAddress wallet = + Address caller = new AionAddress(owners.get(0).getAddress()); + Address wallet = createMultiSigWallet(owners, MultiSignatureContract.MIN_OWNERS, DEFAULT_BALANCE); - AionAddress stranger = getExistentAddress(BigInteger.ZERO); + Address stranger = getExistentAddress(BigInteger.ZERO); // Everyone signs a valid recipient and whole tx is fine but the recipient stated in input // differs. @@ -1194,8 +1196,8 @@ public void testSendTxAllSignWrongRecipient() { @Test public void testSendTxAllSignWrongAmount() { List owners = produceKeys(MultiSignatureContract.MIN_OWNERS); - AionAddress caller = new AionAddress(owners.get(0).getAddress()); - AionAddress wallet = + Address caller = new AionAddress(owners.get(0).getAddress()); + Address wallet = createMultiSigWallet(owners, MultiSignatureContract.MIN_OWNERS, DEFAULT_BALANCE); // Everyone signs a valid amount and whole tx is fine but the amount stated in input @@ -1220,10 +1222,10 @@ public void testSendTxAllSignWrongAmount() { @Test public void testSendTxAllSignWrongNonce() { List owners = produceKeys(MultiSignatureContract.MIN_OWNERS); - AionAddress caller = new AionAddress(owners.get(0).getAddress()); - AionAddress wallet = + Address caller = new AionAddress(owners.get(0).getAddress()); + Address wallet = createMultiSigWallet(owners, MultiSignatureContract.MIN_OWNERS, DEFAULT_BALANCE); - AionAddress stranger = getExistentAddress(BigInteger.ZERO); + Address stranger = getExistentAddress(BigInteger.ZERO); // Everyone signs a different nonce than the wallet's current one. BigInteger nonce = repo.getNonce(wallet); @@ -1247,8 +1249,8 @@ public void testSendTxAllSignWrongNonce() { @Test public void testSendTxAllSignWrongNrgPrice() { List owners = produceKeys(MultiSignatureContract.MIN_OWNERS); - AionAddress caller = new AionAddress(owners.get(0).getAddress()); - AionAddress wallet = + Address caller = new AionAddress(owners.get(0).getAddress()); + Address wallet = createMultiSigWallet(owners, MultiSignatureContract.MIN_OWNERS, DEFAULT_BALANCE); // Everyone signs a valid NRG_PRICE and whole tx is fine but the NRG_PRICE stated in input @@ -1274,8 +1276,8 @@ public void testSendTxAllSignWrongNrgPrice() { public void testSendTxInsufficientBalance() { // Create account with zero balance. List owners = produceKeys(MultiSignatureContract.MIN_OWNERS); - AionAddress caller = new AionAddress(owners.get(0).getAddress()); - AionAddress wallet = + Address caller = new AionAddress(owners.get(0).getAddress()); + Address wallet = createMultiSigWallet(owners, MultiSignatureContract.MIN_THRESH, BigInteger.ZERO); byte[] txMsg = @@ -1298,10 +1300,10 @@ public void testSendTxInsufficientBalance() { public void testWalletAbleToSendTxToDiffWallet() { List owners1 = produceKeys(MultiSignatureContract.MIN_OWNERS); List owners2 = produceKeys(MultiSignatureContract.MIN_OWNERS); - AionAddress caller = new AionAddress(owners1.get(0).getAddress()); - AionAddress wallet1 = + Address caller = new AionAddress(owners1.get(0).getAddress()); + Address wallet1 = createMultiSigWallet(owners1, MultiSignatureContract.MIN_THRESH, DEFAULT_BALANCE); - AionAddress wallet2 = + Address wallet2 = createMultiSigWallet(owners2, MultiSignatureContract.MIN_THRESH, DEFAULT_BALANCE); // Sign tx to send from wallet1 to wallet2. @@ -1325,8 +1327,8 @@ public void testWalletAbleToSendTxToDiffWallet() { @Test public void testSendTxLessSignaturesThanThresholdMinOwners() { List owners = produceKeys(MultiSignatureContract.MIN_OWNERS); - AionAddress caller = new AionAddress(owners.get(0).getAddress()); - AionAddress wallet = + Address caller = new AionAddress(owners.get(0).getAddress()); + Address wallet = createMultiSigWallet(owners, MultiSignatureContract.MIN_OWNERS, DEFAULT_BALANCE); // Have 1 less owner than required sign the tx msg. @@ -1350,8 +1352,8 @@ public void testSendTxLessSignaturesThanThresholdMinOwners() { @Test public void testSendTxLessSignaturesThanThresholdMaxOwners() { List owners = produceKeys(MultiSignatureContract.MAX_OWNERS); - AionAddress caller = new AionAddress(owners.get(0).getAddress()); - AionAddress wallet = + Address caller = new AionAddress(owners.get(0).getAddress()); + Address wallet = createMultiSigWallet(owners, MultiSignatureContract.MAX_OWNERS, DEFAULT_BALANCE); // Have 1 less owner than required sign the tx msg. @@ -1375,8 +1377,8 @@ public void testSendTxLessSignaturesThanThresholdMaxOwners() { @Test public void testSendTxSameSignaturesAsThresholdMinOwners() { List owners = produceKeys(MultiSignatureContract.MIN_OWNERS); - AionAddress caller = new AionAddress(owners.get(0).getAddress()); - AionAddress wallet = + Address caller = new AionAddress(owners.get(0).getAddress()); + Address wallet = createMultiSigWallet(owners, MultiSignatureContract.MIN_THRESH, DEFAULT_BALANCE); // Have each owner sign the tx msg. @@ -1399,8 +1401,8 @@ public void testSendTxSameSignaturesAsThresholdMinOwners() { @Test public void testSendTxSameSignaturesAsThresholdMaxOwners() { List owners = produceKeys(MultiSignatureContract.MAX_OWNERS); - AionAddress caller = new AionAddress(owners.get(0).getAddress()); - AionAddress wallet = + Address caller = new AionAddress(owners.get(0).getAddress()); + Address wallet = createMultiSigWallet(owners, MultiSignatureContract.MAX_OWNERS, DEFAULT_BALANCE); // Have each owner sign the tx msg. @@ -1423,8 +1425,8 @@ public void testSendTxSameSignaturesAsThresholdMaxOwners() { @Test public void testSendTxMoreSignaturesThanThresholdMinOwners() { List owners = produceKeys(MultiSignatureContract.MIN_OWNERS); - AionAddress caller = new AionAddress(owners.get(0).getAddress()); - AionAddress wallet = + Address caller = new AionAddress(owners.get(0).getAddress()); + Address wallet = createMultiSigWallet( owners, MultiSignatureContract.MIN_OWNERS - 1, DEFAULT_BALANCE); @@ -1448,8 +1450,8 @@ public void testSendTxMoreSignaturesThanThresholdMinOwners() { @Test public void testSendTxMoreSignaturesThanThresholdMaxOwners() { List owners = produceKeys(MultiSignatureContract.MAX_OWNERS); - AionAddress caller = new AionAddress(owners.get(0).getAddress()); - AionAddress wallet = + Address caller = new AionAddress(owners.get(0).getAddress()); + Address wallet = createMultiSigWallet(owners, MultiSignatureContract.MIN_THRESH, DEFAULT_BALANCE); // Have all the owners sign. @@ -1472,8 +1474,8 @@ public void testSendTxMoreSignaturesThanThresholdMaxOwners() { @Test public void testSendTxDuplicateSignee() { List owners = produceKeys(MultiSignatureContract.MAX_OWNERS); - AionAddress caller = new AionAddress(owners.get(0).getAddress()); - AionAddress wallet = + Address caller = new AionAddress(owners.get(0).getAddress()); + Address wallet = createMultiSigWallet(owners, MultiSignatureContract.MAX_OWNERS, DEFAULT_BALANCE); // All owners but 1 sign, and 1 signs twice to meet threshold req. @@ -1499,8 +1501,8 @@ public void testSendTxDuplicateSignee() { public void testSendTxSignatureOneSigneeIsNonOwner() { List owners = produceKeys(MultiSignatureContract.MAX_OWNERS); ECKeyEd25519 phony = produceKeys(1).get(0); - AionAddress caller = new AionAddress(owners.get(0).getAddress()); - AionAddress wallet = + Address caller = new AionAddress(owners.get(0).getAddress()); + Address wallet = createMultiSigWallet(owners, MultiSignatureContract.MAX_OWNERS, DEFAULT_BALANCE); // All owners but 1 sign, and then the phony signs. @@ -1526,8 +1528,8 @@ public void testSendTxSignatureOneSigneeIsNonOwner() { @Test public void testSendTxSignedProperlyButNotSignedByOwnerCaller() { List owners = produceKeys(MultiSignatureContract.MAX_OWNERS); - AionAddress caller = new AionAddress(owners.get(0).getAddress()); - AionAddress wallet = + Address caller = new AionAddress(owners.get(0).getAddress()); + Address wallet = createMultiSigWallet(owners, MultiSignatureContract.MIN_THRESH, DEFAULT_BALANCE); // Adequate number of signees but we skip signee 0 since they are caller. @@ -1554,7 +1556,7 @@ public void testSendTxSignedProperlyButNotSignedByOwnerCaller() { public void testSendTxSignedProperlyButCallerIsNotOwner() { List owners = produceKeys(MultiSignatureContract.MIN_OWNERS); ECKeyEd25519 phony = produceKeys(1).get(0); - AionAddress wallet = + Address wallet = createMultiSigWallet(owners, MultiSignatureContract.MIN_OWNERS, DEFAULT_BALANCE); // Signed adequately. @@ -1571,7 +1573,12 @@ public void testSendTxSignedProperlyButCallerIsNotOwner() { checkAccountState(wallet, BigInteger.ZERO, DEFAULT_BALANCE); checkAccountState(to, BigInteger.ZERO, BigInteger.ZERO); - execute(new AionAddress(phony.getAddress()), input, NRG_LIMIT, PrecompiledResultCode.FAILURE, 0); + execute( + new AionAddress(phony.getAddress()), + input, + NRG_LIMIT, + PrecompiledResultCode.FAILURE, + 0); checkAccountState(wallet, BigInteger.ZERO, DEFAULT_BALANCE); checkAccountState(to, BigInteger.ZERO, BigInteger.ZERO); } @@ -1579,8 +1586,8 @@ public void testSendTxSignedProperlyButCallerIsNotOwner() { @Test public void testPartialSignature() { List owners = produceKeys(MultiSignatureContract.MIN_OWNERS); - AionAddress caller = new AionAddress(owners.get(0).getAddress()); - AionAddress wallet = + Address caller = new AionAddress(owners.get(0).getAddress()); + Address wallet = createMultiSigWallet(owners, MultiSignatureContract.MIN_OWNERS, DEFAULT_BALANCE); // Signed adequately. @@ -1594,7 +1601,7 @@ public void testPartialSignature() { byte[] input = MultiSignatureContract.constructSendTxInput( wallet, signatures, AMOUNT, NRG_PRICE, to); - int amtStart = input.length - AionAddress.SIZE - Long.BYTES - AMT_SIZE; + int amtStart = input.length - Address.SIZE - Long.BYTES - AMT_SIZE; byte[] shiftedInput = shiftLeftAtIndex(input, amtStart); checkAccountState(wallet, BigInteger.ZERO, DEFAULT_BALANCE); @@ -1607,8 +1614,8 @@ public void testPartialSignature() { @Test public void testPartialWalletAddress() { List owners = produceKeys(MultiSignatureContract.MIN_OWNERS); - AionAddress caller = new AionAddress(owners.get(0).getAddress()); - AionAddress wallet = + Address caller = new AionAddress(owners.get(0).getAddress()); + Address wallet = createMultiSigWallet(owners, MultiSignatureContract.MIN_OWNERS, DEFAULT_BALANCE); // Signed adequately. @@ -1622,7 +1629,7 @@ public void testPartialWalletAddress() { byte[] input = MultiSignatureContract.constructSendTxInput( wallet, signatures, AMOUNT, NRG_PRICE, to); - int sigsStart = 1 + AionAddress.SIZE; + int sigsStart = 1 + Address.SIZE; byte[] shiftedInput = shiftLeftAtIndex(input, sigsStart); checkAccountState(wallet, BigInteger.ZERO, DEFAULT_BALANCE); @@ -1635,8 +1642,8 @@ public void testPartialWalletAddress() { @Test public void testPartialRecipientAddress() { List owners = produceKeys(MultiSignatureContract.MIN_OWNERS); - AionAddress caller = new AionAddress(owners.get(0).getAddress()); - AionAddress wallet = + Address caller = new AionAddress(owners.get(0).getAddress()); + Address wallet = createMultiSigWallet(owners, MultiSignatureContract.MIN_OWNERS, DEFAULT_BALANCE); // Signed adequately. @@ -1663,8 +1670,8 @@ public void testPartialRecipientAddress() { @Test public void testPartialAmount() { List owners = produceKeys(MultiSignatureContract.MIN_OWNERS); - AionAddress caller = new AionAddress(owners.get(0).getAddress()); - AionAddress wallet = + Address caller = new AionAddress(owners.get(0).getAddress()); + Address wallet = createMultiSigWallet(owners, MultiSignatureContract.MIN_OWNERS, DEFAULT_BALANCE); // Signed adequately. @@ -1678,7 +1685,7 @@ public void testPartialAmount() { byte[] input = MultiSignatureContract.constructSendTxInput( wallet, signatures, AMOUNT, NRG_PRICE, to); - int nrgStart = input.length - AionAddress.SIZE - Long.BYTES; + int nrgStart = input.length - Address.SIZE - Long.BYTES; byte[] shiftedInput = shiftLeftAtIndex(input, nrgStart); checkAccountState(wallet, BigInteger.ZERO, DEFAULT_BALANCE); @@ -1691,8 +1698,8 @@ public void testPartialAmount() { @Test public void testPartialNrgPrice() { List owners = produceKeys(MultiSignatureContract.MIN_OWNERS); - AionAddress caller = new AionAddress(owners.get(0).getAddress()); - AionAddress wallet = + Address caller = new AionAddress(owners.get(0).getAddress()); + Address wallet = createMultiSigWallet(owners, MultiSignatureContract.MIN_OWNERS, DEFAULT_BALANCE); // Signed adequately. @@ -1706,7 +1713,7 @@ public void testPartialNrgPrice() { byte[] input = MultiSignatureContract.constructSendTxInput( wallet, signatures, AMOUNT, NRG_PRICE, to); - int toStart = input.length - AionAddress.SIZE; + int toStart = input.length - Address.SIZE; byte[] shiftedInput = shiftLeftAtIndex(input, toStart); checkAccountState(wallet, BigInteger.ZERO, DEFAULT_BALANCE); diff --git a/modPrecompiled/test/org/aion/precompiled/contracts/TotalCurrencyContractTest.java b/modPrecompiled/test/org/aion/precompiled/contracts/TotalCurrencyContractTest.java index d13b2317f2..004fbd6472 100644 --- a/modPrecompiled/test/org/aion/precompiled/contracts/TotalCurrencyContractTest.java +++ b/modPrecompiled/test/org/aion/precompiled/contracts/TotalCurrencyContractTest.java @@ -5,14 +5,15 @@ import java.math.BigInteger; import java.nio.ByteBuffer; import java.util.Arrays; -import org.aion.base.type.AionAddress; import org.aion.base.db.IRepositoryCache; +import org.aion.base.type.AionAddress; import org.aion.crypto.ECKey; import org.aion.crypto.ECKeyFac; import org.aion.mcf.vm.types.DataWord; import org.aion.precompiled.ContractFactory; import org.aion.precompiled.PrecompiledResultCode; import org.aion.precompiled.PrecompiledTransactionResult; +import org.aion.vm.api.interfaces.Address; import org.junit.After; import org.junit.Before; import org.junit.Ignore; @@ -20,7 +21,7 @@ @Ignore public class TotalCurrencyContractTest { - private static final AionAddress ADDR = ContractFactory.getTotalCurrencyContractAddress(); + private static final Address ADDR = ContractFactory.getTotalCurrencyContractAddress(); private static final long COST = 21000L; private static final BigInteger AMT = BigInteger.valueOf(1000); private TotalCurrencyContract tcc; @@ -274,7 +275,8 @@ public void TestUpdateMultipleChains() { tcc.execute(input2, COST); tcc.execute(input2, COST); - PrecompiledTransactionResult res = tcc.execute(new byte[] {(byte) 0x0}, COST); // get chain 0. + PrecompiledTransactionResult res = + tcc.execute(new byte[] {(byte) 0x0}, COST); // get chain 0. assertEquals(PrecompiledResultCode.SUCCESS, res.getResultCode()); assertEquals(AMT, new BigInteger(res.getOutput())); diff --git a/modVM/src/org/aion/vm/ExecutionBatch.java b/modVM/src/org/aion/vm/ExecutionBatch.java index 04352b27eb..6d47ebec14 100644 --- a/modVM/src/org/aion/vm/ExecutionBatch.java +++ b/modVM/src/org/aion/vm/ExecutionBatch.java @@ -3,7 +3,6 @@ import java.util.ArrayList; import java.util.Arrays; import java.util.List; -import org.aion.base.type.AionAddress; import org.aion.fastvm.ExecutionContext; import org.aion.mcf.vm.types.DataWord; import org.aion.util.bytes.ByteUtil; @@ -140,7 +139,7 @@ private KernelTransactionContext constructTransactionContext( : ExecutionContext.CALL; int flags = 0; - AionAddress blockCoinbase = block.getCoinbase(); + Address blockCoinbase = block.getCoinbase(); long blockNumber = block.getNumber(); long blockTimestamp = block.getTimestamp(); long blockNrgLimit = block.getNrgLimit(); diff --git a/modVM/src/org/aion/vm/KernelTransactionContext.java b/modVM/src/org/aion/vm/KernelTransactionContext.java index 274c5e0b9f..018cb823ac 100644 --- a/modVM/src/org/aion/vm/KernelTransactionContext.java +++ b/modVM/src/org/aion/vm/KernelTransactionContext.java @@ -3,7 +3,6 @@ import java.math.BigInteger; import java.nio.ByteBuffer; import java.nio.ByteOrder; -import org.aion.base.type.AionAddress; import org.aion.base.vm.IDataWord; import org.aion.fastvm.SideEffects; import org.aion.mcf.vm.types.DataWord; @@ -15,7 +14,7 @@ public class KernelTransactionContext implements TransactionContext { private static final int ENCODE_BASE_LEN = - (AionAddress.SIZE * 4) + (DataWord.BYTES * 3) + (Long.BYTES * 4) + (Integer.BYTES * 4); + (Address.SIZE * 4) + (DataWord.BYTES * 3) + (Long.BYTES * 4) + (Integer.BYTES * 4); public static int CALL = 0; public static int DELEGATECALL = 1; public static int CALLCODE = 2;