Skip to content

Commit fcf3366

Browse files
fix(json-rpc): fix address generation of contract which created by create2
1 parent ecbb194 commit fcf3366

2 files changed

Lines changed: 24 additions & 1 deletion

File tree

framework/src/main/java/org/tron/core/services/jsonrpc/TronJsonRpcImpl.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -496,6 +496,7 @@ public String getStorageAt(String address, String storageIdx, String blockNumOrT
496496
StorageRowStore store = manager.getStorageRowStore();
497497
Storage storage = new Storage(addressByte, store);
498498
storage.setContractVersion(smartContract.getVersion());
499+
storage.generateAddrHash(smartContract.getTrxHash().toByteArray());
499500

500501
DataWord value = storage.getValue(new DataWord(ByteArray.fromHexString(storageIdx)));
501502
return ByteArray.toJsonHex(value == null ? new byte[32] : value.getData());

framework/src/test/java/org/tron/common/runtime/vm/Create2Test.java

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,16 @@
1111
import org.testng.Assert;
1212
import org.tron.common.runtime.TVMTestResult;
1313
import org.tron.common.runtime.TvmTestUtils;
14+
import org.tron.common.utils.ByteArray;
1415
import org.tron.common.utils.WalletUtil;
16+
import org.tron.core.Wallet;
1517
import org.tron.core.exception.ContractExeException;
1618
import org.tron.core.exception.ContractValidateException;
19+
import org.tron.core.exception.JsonRpcInvalidParamsException;
1720
import org.tron.core.exception.ReceiptCheckErrException;
1821
import org.tron.core.exception.VMIllegalException;
22+
import org.tron.core.services.NodeInfoService;
23+
import org.tron.core.services.jsonrpc.TronJsonRpcImpl;
1924
import org.tron.protos.Protocol.Transaction;
2025
import stest.tron.wallet.common.client.utils.AbiUtil;
2126
import stest.tron.wallet.common.client.utils.DataWord;
@@ -171,14 +176,31 @@ public void testCreate2()
171176

172177
// trigger deployed contract
173178
String methodToTrigger = "plusOne()";
174-
for (int i = 1; i < 3; i++) {
179+
long loop = 2;
180+
for (int i = 1; i <= loop; i++) {
175181
hexInput = AbiUtil.parseMethod(methodToTrigger, Collections.emptyList());
176182
result = TvmTestUtils
177183
.triggerContractAndReturnTvmTestResult(Hex.decode(OWNER_ADDRESS),
178184
actualContract, Hex.decode(hexInput), 0, fee, manager, null);
179185
Assert.assertNull(result.getRuntime().getRuntimeError());
180186
Assert.assertEquals(result.getRuntime().getResult().getHReturn(), new DataWord(i).getData());
181187
}
188+
testJsonRpc(actualContract, loop);
189+
}
190+
191+
private void testJsonRpc(byte[] actualContract, long loop) {
192+
TronJsonRpcImpl tronJsonRpc;
193+
NodeInfoService nodeInfoService;
194+
nodeInfoService = context.getBean(NodeInfoService.class);
195+
Wallet wallet = context.getBean(Wallet.class);
196+
tronJsonRpc = new TronJsonRpcImpl(nodeInfoService, wallet, manager);
197+
try {
198+
String res =
199+
tronJsonRpc.getStorageAt(ByteArray.toHexString(actualContract), "0", "latest");
200+
Assert.assertEquals(loop, ByteArray.jsonHexToLong(res));
201+
} catch (JsonRpcInvalidParamsException e) {
202+
Assert.fail();
203+
}
182204
}
183205

184206
/*

0 commit comments

Comments
 (0)