backend_update_260130
This commit is contained in:
@@ -51,16 +51,16 @@ def create_asset(token, title, private_key_shard, content_inner_encrypted):
|
||||
print(f"Failed to create asset: {response.text}")
|
||||
return None
|
||||
|
||||
def assign_heir(token, asset_id, heir_name):
|
||||
def assign_heir(token, asset_id, heir_email):
|
||||
url = f"{BASE_URL}/assets/assign"
|
||||
headers = {"Authorization": f"Bearer {token}"}
|
||||
data = {
|
||||
"asset_id": asset_id,
|
||||
"heir_name": heir_name
|
||||
"heir_email": heir_email
|
||||
}
|
||||
response = requests.post(url, json=data, headers=headers)
|
||||
if response.status_code == 200:
|
||||
print(f"Asset {asset_id} assigned to heir {heir_name} successfully.")
|
||||
print(f"Asset {asset_id} assigned to heir {heir_email} successfully.")
|
||||
return response.json()
|
||||
else:
|
||||
print(f"Failed to assign heir: {response.text}")
|
||||
@@ -105,6 +105,17 @@ def get_my_assets(token):
|
||||
print(f"Failed to retrieve assets: {response.text}")
|
||||
return None
|
||||
|
||||
def get_designated_assets(token):
|
||||
url = f"{BASE_URL}/assets/designated"
|
||||
headers = {"Authorization": f"Bearer {token}"}
|
||||
response = requests.get(url, headers=headers)
|
||||
if response.status_code == 200:
|
||||
print(f"Designated assets retrieved successfully.")
|
||||
return response.json()
|
||||
else:
|
||||
print(f"Failed to retrieve designated assets: {response.text}")
|
||||
return None
|
||||
|
||||
def main():
|
||||
# 1. 创建三个用户
|
||||
users = [
|
||||
@@ -143,7 +154,7 @@ def main():
|
||||
if not token1:
|
||||
return
|
||||
|
||||
# 3. 创建一个 asset
|
||||
# 3. 创建三个 asset
|
||||
asset1 = create_asset(
|
||||
token1,
|
||||
"My Secret Asset1",
|
||||
@@ -158,23 +169,42 @@ def main():
|
||||
ciphertext_1
|
||||
)
|
||||
|
||||
if not asset1 or not asset2:
|
||||
asset3 = create_asset(
|
||||
token1,
|
||||
"My Secret Asset3",
|
||||
share_a,
|
||||
ciphertext_1
|
||||
)
|
||||
|
||||
if not asset1 or not asset2 or not asset3:
|
||||
print(" [失败] 创建资产失败")
|
||||
return
|
||||
|
||||
|
||||
# 3.1 测试 /assets/get
|
||||
print("\n [测试] 获取用户资产列表")
|
||||
my_assets = get_my_assets(token1)
|
||||
if my_assets:
|
||||
print(f" [输出] 成功获取 {len(my_assets)} 个资产")
|
||||
user1_assets = get_my_assets(token1)
|
||||
if user1_assets:
|
||||
print(f" [输出] 用户1共有 {len(user1_assets)} 个资产")
|
||||
else:
|
||||
print(" [失败] 无法获取资产列表")
|
||||
|
||||
# 4. 指定用户 2 为继承人
|
||||
print("用户 1 指定用户 2 为继承人")
|
||||
assign_heir(token1, asset1["id"], "user2")
|
||||
|
||||
print("用户 1 为用户 2 分配遗产")
|
||||
assign_heir(token1, asset1["id"], "user2@example.com")
|
||||
assign_heir(token1, asset2["id"], "user2@example.com")
|
||||
|
||||
# 4.1 用户2查询自己能继承多少遗产
|
||||
print("\n [测试] 用户 2 查询自己被指定的资产")
|
||||
token2_temp = login_user("user2", "pass123")
|
||||
designated_assets = get_designated_assets(token2_temp)
|
||||
if designated_assets:
|
||||
print(f" [输出] 用户 2 共有 {len(designated_assets)} 个被指定的资产")
|
||||
for asset in designated_assets:
|
||||
print(f" - Asset ID: {asset['id']}, Title: {asset['title']}")
|
||||
else:
|
||||
print(" [失败] 无法获取被指定资产列表")
|
||||
|
||||
|
||||
print("\n## 3. 继承流 (Inheritance Layer)")
|
||||
# 5. Admin 宣布用户 1 挂了
|
||||
print("Admin 宣布用户 1 挂了")
|
||||
|
||||
Reference in New Issue
Block a user