修正RPC响应失败

This commit is contained in:
lu7213 committed 2026-10-28 11:12:50 -04:00
1 parent 1e79e836e8
commit 911a3634ee
5 files changed
+124 -21

No files matched your search

@@ -34,6 +34,7 @@ public class RentalHistoryTest {
private boolean invalidParameters;
private boolean rpcFailure;
private int calls;
private long confirmationLag;
@Before
public void setup() throws Exception {
@@ -61,14 +62,18 @@ public class RentalHistoryTest {
}
if (path.endsWith("getnowblock")) {
long height = changingHeads > 0 ? currentHead + changingHeads-- : currentHead;
if (path.startsWith("/walletsolidity/")) {
height -= confirmationLag;
}
return block(height);
}
if (path.endsWith("getaccountresource")) {
assertEquals("/wallet/getaccountresource", path);
return json.valueToTree(invalidParameters ? map("TotalEnergyLimit", 0)
: map("TotalEnergyLimit", energyLimit, "TotalEnergyWeight", 1000000,
"TotalNetLimit", 1500000, "TotalNetWeight", 1000000));
}
if (path.equals("/walletsolidity/getdelegatedresourcev2")) {
if (path.equals("/wallet/getdelegatedresourcev2")) {
return json.valueToTree(Boolean.TRUE.equals(body.get("lock")) ? map()
: map("delegatedResource", Arrays.asList(map("frozen_balance_for_energy", relation))));
}
@@ -157,6 +162,45 @@ public class RentalHistoryTest {
}
}
@Test
public void fullNodeSamplesWaitForConfirmationWithoutRelabelingParameters() {
confirmationLag = 2;
rejects(this::anchor);
assertEquals(0, number(store.one("SELECT COUNT(*) AS n FROM rent_history_anchor"), "n"));
currentHead = 101;
energyLimit = 90000000;
rejects(this::anchor);
currentHead = 102;
anchor();
Map<String, Object> saved = store.one("SELECT * FROM rent_history_anchor");
assertEquals(100, number(saved, "block_height"));
assertEquals(60000000, number(store.one("SELECT * FROM rent_history_block WHERE block_height=100"), "energy_limit"));
}
@Test
public void collectionKeepsSamplingWhileWaitingAndArchivesOriginalHeight() {
confirmationLag = 2;
rejects(() -> collect(100));
energyLimit = 90000000;
rejects(() -> collect(101));
collect(102);
assertEquals(100, number(service.status().get(0), "scanned_height"));
assertEquals(60000000, number(store.one("SELECT * FROM rent_history_block WHERE block_height=100"), "energy_limit"));
collect(103);
assertEquals(101, number(service.status().get(0), "scanned_height"));
assertEquals(90000000, number(store.one("SELECT * FROM rent_history_block WHERE block_height=101"), "energy_limit"));
}
@Test
public void forkedUnconfirmedSampleCannotBecomeEvidence() {
confirmationLag = 2;
rejects(this::anchor);
((ObjectNode) block(100)).put("blockID", hash(999));
currentHead = 102;
rejects(this::anchor);
assertEquals(0, number(store.one("SELECT COUNT(*) AS n FROM rent_history_anchor"), "n"));
}
@Test
public void coherentArchiveProducesProofAndPreservesOldParameters() {
anchor();
@@ -399,6 +443,7 @@ public class RentalHistoryTest {
chain.prepareHistory("NILE", OWNER, RECEIVER, "ENERGY");
transactions(101, event(1001, "DelegateResourceContract", "ENERGY", SUN));
collect(101);
relation = SUN;
Map<String, Object> verified = chain.verify(map("network", "NILE", "task_type", "DELEGATE",
"delegate_sun", SUN, "resource_type", "ENERGY"), hash(1001), OWNER, RECEIVER);
assertEquals(Boolean.TRUE, verified.get("delivery_proven"));
@@ -413,6 +458,7 @@ public class RentalHistoryTest {
collect(100);
transactions(101, event(1001, "DelegateResourceContract", "ENERGY", SUN));
collect(102);
relation = SUN;
Map<String, Object> verified = chain.verify(map("network", "NILE", "task_type", "DELEGATE",
"delegate_sun", SUN, "resource_type", "ENERGY"), hash(1001), OWNER, RECEIVER);
assertEquals("CONFIRMED", verified.get("status"));