1. 请在views/rental/nodeDetail 页面添加出租设置功能 2. 一个租赁节点只能绑定一个钱包地址,添加验证和页面布局,请修改views/rental/nodeDetail 页面,并添加换绑功能。

This commit is contained in:
lu7213 committed 2026-10-30 20:25:31 -04:00
1 parent 624110e43c
commit 4b6ea31e6a
4 files changed
+163

No files matched your search

@@ -65,6 +65,73 @@ public class RentalBusinessTest {
assertEquals(1, store.rows("SELECT id FROM rent_event WHERE object_type='WALLET' AND object_id=? AND action='DELETE'", pending).size());
}
/** 同一节点新增必须串行校验;两个并发请求只能成功绑定一个地址。 */
@Test
public void concurrentWalletRegistrationAllowsOnlyOne() throws Exception {
long freshNode = tx.execute(status -> rentalDeletion().create("node", map("name", "single-wallet"), 20));
ExecutorService pool = Executors.newFixedThreadPool(2);
CountDownLatch start = new CountDownLatch(1);
try {
List<Future<Boolean>> results = new ArrayList<>();
for (String address : Arrays.asList(ADDRESS, "T9yD14Nj9j7xAB4dbGeiX9h8unkKHxuWwb")) {
results.add(pool.submit(() -> {
start.await();
try {
tx.execute(status -> rentalDeletion().create("wallet", map("node_id", freshNode,
"network", "MAINNET", "address", address), 20));
return true;
} catch (IllegalArgumentException expected) { return false; }
}));
}
start.countDown();
int successes = 0;
for (Future<Boolean> result : results) { if (result.get(15, TimeUnit.SECONDS)) successes++; }
assertEquals(1, successes);
assertEquals(1, store.rows("SELECT id FROM rent_wallet WHERE node_id=?", freshNode).size());
} finally { pool.shutdownNow(); }
}
/** 换绑重置旧地址认证及资源策略,拒绝在线、越权、错误网络、重复地址及历史业务关联。 */
@Test
public void walletRebindResetsProofAndRejectsUnsafeChanges() {
Map<String, Object> request = map("network", "NILE", "address", ADDRESS);
expectFailure(() -> tx.execute(status -> { rentalDeletion().rebindWallet(wallet, request, 20); return null; }));
store.update("node", node, map("connection_status", "OFFLINE"));
expectFailure(() -> tx.execute(status -> { rentalDeletion().rebindWallet(wallet, request, 10); return null; }));
expectFailure(() -> tx.execute(status -> { rentalDeletion().rebindWallet(wallet, map("network", "MAINNET", "address", ADDRESS), 20); return null; }));
expectFailure(() -> tx.execute(status -> { rentalDeletion().rebindWallet(wallet, map("network", "NILE", "address", OWNER), 20); return null; }));
store.update("wallet", wallet, map("energy_reserved_sun", 1));
expectFailure(() -> tx.execute(status -> { rentalDeletion().rebindWallet(wallet, request, 20); return null; }));
store.update("wallet", wallet, map("energy_reserved_sun", 0, "ownership_challenge", "old-challenge"));
tx.execute(status -> { rentalDeletion().rebindWallet(wallet, request, 20); return null; });
Map<String, Object> updated = store.get("wallet", wallet, false);
assertEquals(ADDRESS, text(updated, "address"));
assertEquals("PENDING", text(updated, "status"));
assertNull(updated.get("ownership_verified_at"));
assertNull(updated.get("ownership_challenge"));
assertNull(updated.get("snapshot_at"));
assertEquals(0, number(updated, "energy_enabled"));
assertEquals(0, number(updated, "energy_delegatable_sun"));
store.update("wallet", wallet, map("status", "ACTIVE", "ownership_verified_at", now()));
Map<String, Object> order = tx.execute(status -> orders.create(app, 10, map("network", "NILE",
"package_id", product, "resource_type", "ENERGY", "merchant_order_no", "rebind-history", "receiver_address", ADDRESS)));
store.update("order", number(order, "id"), map("wallet_id", wallet));
expectFailure(() -> tx.execute(status -> { rentalDeletion().rebindWallet(wallet, map("network", "NILE", "address", OWNER), 20); return null; }));
assertEquals(ADDRESS, text(store.get("wallet", wallet, false), "address"));
}
/** 出租策略保留 SUN 整数精度,不能越权或写入负数/小数。 */
@Test
public void walletPolicyIsOwnedAndUsesExactSun() {
Map<String, Object> policy = map("energy_enabled", 1, "bandwidth_enabled", 0,
"energy_retain_sun", "9007199254740993", "bandwidth_retain_sun", "0");
expectFailure(() -> tx.execute(status -> { rentalDeletion().policy(wallet, policy, 10); return null; }));
tx.execute(status -> { rentalDeletion().policy(wallet, policy, 20); return null; });
assertEquals(9007199254740993L, number(store.get("wallet", wallet, false), "energy_retain_sun"));
policy.put("bandwidth_retain_sun", "-1");
expectFailure(() -> tx.execute(status -> { rentalDeletion().policy(wallet, policy, 20); return null; }));
}
/** 在线和恢复连接时拒绝轮换且保留原凭证,离线后允许正常轮换。 */
@Test
public void nodeCredentialRotationRequiresOffline() {
@@ -99,6 +166,17 @@ public class RentalBusinessTest {
tx.execute(status -> identity.issue("NODE", node, 20));
RentalController controller = new RentalController(
store, null, identity, orders, funds, reviews, tasks, null, null);
expectFailure(() -> controller.nodeDetail(node));
long ownNode = tx.execute(status -> rentalDeletion().create("node", map("name", "owned-detail"), 10));
long ownWallet = tx.execute(status -> rentalDeletion().create("wallet", map("node_id", ownNode,
"network", "MAINNET", "address", ADDRESS), 10));
store.update("wallet", ownWallet, map("ownership_challenge", "hidden-challenge", "ownership_signature", "hidden-signature"));
Map<String, Object> detail = (Map<String, Object>) controller.nodeDetail(ownNode).get("data");
List<Map<String, Object>> wallets = (List<Map<String, Object>>) detail.get("wallets");
assertEquals(1, wallets.size());
assertEquals(ownWallet, number(wallets.get(0), "id"));
assertFalse(wallets.get(0).containsKey("ownership_challenge"));
assertFalse(wallets.get(0).containsKey("ownership_signature"));
Map<String, Object> result = (Map<String, Object>) controller.appDetail(app).get("data");
Map<String, Object> appDetail = (Map<String, Object>) result.get("app");
assertEquals(time(store.get("app", app, false).get("created_at")).toEpochMilli(),