-
Notifications
You must be signed in to change notification settings - Fork 70
[WIP] Chore/fix commit tests #391
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
ed63843
9449c72
1cf9a9e
9825210
a49fb11
850c8c6
099c914
05059ea
6050b04
2e647c5
6316b99
ec5ec2e
0354608
01cac9c
7093560
298b285
cd4567d
4bab546
ce12875
7ecbfd7
9fda522
c856747
27d9cd9
d1bf234
f74552d
ac46176
cb68bae
8a364ad
8558b76
6238630
9b93b95
bc12bb6
3e74cfe
d1fed93
1f1af4f
06bc514
ddef325
463fd44
77368fd
cb7b5df
aa44a09
8707871
706dbb8
6ec66b0
6878098
3704c6b
5b6e81d
e62ede3
31e23d7
8def34a
38cf678
b0b2820
0e940ff
648914c
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -3,13 +3,14 @@ | |
|
|
||
| -- Find the user's balance in the current ledger state. | ||
| function balance(base, request) | ||
| ao.event({ "Client received balance request" }) | ||
|
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. start improved hyper-token lua events |
||
| local status, res = ao.resolve({ | ||
| path = | ||
| base["ledger-path"] | ||
| .. "/now/balance/" | ||
| .. request["target"] | ||
| }) | ||
| ao.event({ "client received balance response", | ||
| ao.event({ "Client received balance response", | ||
| { status = status, res = res, target = request["target"] } } | ||
| ) | ||
| -- If the balance request fails (most likely because the user has no balance), | ||
|
|
@@ -25,7 +26,7 @@ end | |
| -- Charge the user's balance in the current ledger state. | ||
| function charge(base, request) | ||
| ao.event("debug_charge", { | ||
| "client starting charge", | ||
| "Client starting charge", | ||
| { request = request, base = base } | ||
| }) | ||
| local status, res = ao.resolve({ | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -294,7 +294,7 @@ end | |
| -- be from our own root ledger, or from a sub-ledger that is precisely the same | ||
| -- as our own. | ||
| local function validate_new_peer_ledger(base, request) | ||
| ao.event({ "Validating peer ledger: ", { request = request } }) | ||
| ao.event({ "Validating peer ledger: ", { action = request.action } }) | ||
|
|
||
| -- Check if the request is from the root ledger. | ||
| if is_root(base) or (base.token == request.from) then | ||
|
|
@@ -308,7 +308,7 @@ local function validate_new_peer_ledger(base, request) | |
| -- modified to remove the `authority' and `scheduler' fields. | ||
| -- This ensures that the process we are receiving the `credit-notice` from | ||
| -- has the same structure as our own process. | ||
| ao.event({ "Calculating expected `base` from self", { base = base } }) | ||
| ao.event({ "Calculating expected `base` from self" }) | ||
| local status, proc, expected | ||
| status, proc = ao.resolve({"as", "[email protected]", base}, "process") | ||
| -- Reset the `authority' and `scheduler' fields to nil, to ensure that the | ||
|
|
@@ -320,12 +320,10 @@ local function validate_new_peer_ledger(base, request) | |
| proc, | ||
| { path = "id", commitments = "none" } | ||
| ) | ||
| ao.event({ "Expected `from-base`", { status = status, expected = expected } }) | ||
| ao.event("debug_base", { "Expected `from-base`", { status = status, expected = expected, proc = proc } }) | ||
| -- Check if the `from-base' field is present in the assignment. | ||
| if not request["from-base"] then | ||
| ao.event({ "`from-base` field not found in message", { | ||
| request = request | ||
| }}) | ||
| ao.event({ "`from-base` field not found in message" }) | ||
| return false | ||
| end | ||
|
|
||
|
|
@@ -474,6 +472,10 @@ function validate_request(incoming_base, assignment) | |
| }) | ||
| end | ||
|
|
||
| ao.event({ "ensure_initialized", { | ||
| status = status, | ||
| base = base | ||
| }}) | ||
| -- First, ensure that the message has not already been processed. | ||
| ao.event("Deduplicating message.", { | ||
| ["history-length"] = #(base.dedup or {}) | ||
|
|
@@ -598,7 +600,8 @@ local function debit_balance(base, request) | |
| if type(source_balance) ~= "number" then | ||
| return "error", log_result(base, "error", { | ||
| message = "Source balance is not a number.", | ||
| balance = source_balance | ||
| balance = source_balance, | ||
| type = type(source_balance) | ||
| }) | ||
| end | ||
|
|
||
|
|
@@ -620,7 +623,7 @@ local function debit_balance(base, request) | |
| }) | ||
| end | ||
|
|
||
| ao.event({ "Deducting funds:", { request = request } }) | ||
| ao.event({ "Deducting funds" }) | ||
| base.balance[source] = source_balance - request.quantity | ||
| ao.event({ "Balances after deduction:", | ||
| { balances = base.balance, ledgers = base.ledgers } } | ||
|
|
@@ -655,10 +658,20 @@ end | |
| -- Xfer in: Sub-ledger = Dec User balance | ||
| -- C-N in: Root = Inc User balance, Dec Sub-ledger balance | ||
| function transfer(base, assignment) | ||
| ao.event({ "Transfer request received", { assignment = assignment } }) | ||
| ao.event({ "Transfer request received", { | ||
| balances = base.balance, | ||
| ledgers = base.ledgers, | ||
| path = assignment.path, | ||
| body = assignment.body | ||
| } }) | ||
| -- Verify the security of the request. | ||
| local status, request | ||
| status, base, request = validate_request(base, assignment) | ||
| ao.event({ "Transfer request validated", { | ||
| status = status, | ||
| balances = base.balance, | ||
| ledgers = base.ledgers | ||
| } }) | ||
| if status ~= "ok" or not request then | ||
| return "ok", base | ||
| end | ||
|
|
@@ -691,6 +704,7 @@ function transfer(base, assignment) | |
| -- another user. We credit the recipient's balance, or the sub-ledger's | ||
| -- balance if the request has a `route' key. | ||
| local direct_recipient = request.route or request.recipient | ||
| ao.event({ "Balances before credit", { balances = base.balance } }) | ||
| base.balance[direct_recipient] = | ||
| (base.balance[direct_recipient] or 0) + quantity | ||
| base = send(base, { | ||
|
|
@@ -700,12 +714,14 @@ function transfer(base, assignment) | |
| quantity = quantity, | ||
| sender = request.from | ||
| }) | ||
| ao.event({ "Balances after credit", { balances = base.balance } }) | ||
| return log_result(base, "ok", { | ||
| message = "Direct or root transfer processed successfully.", | ||
| from_user = request.from, | ||
| to = direct_recipient, | ||
| explicit_recipient = request.recipient, | ||
| quantity = quantity | ||
| quantity = quantity, | ||
| balances = base.balance | ||
| }) | ||
| end | ||
|
|
||
|
|
@@ -750,7 +766,7 @@ end | |
|
|
||
| -- Process credit notices from other ledgers. | ||
| _G["credit-notice"] = function (base, assignment) | ||
| ao.event({ "Credit-Notice received", { assignment = assignment } }) | ||
| ao.event({ "Credit-Notice received" }) | ||
|
|
||
| -- Verify the security of the request. | ||
| local status, request | ||
|
|
@@ -801,7 +817,8 @@ _G["credit-notice"] = function (base, assignment) | |
| to_ledger = request.sender, | ||
| to_user = request.recipient, | ||
| quantity = quantity, | ||
| balance = base.balance[request.recipient] | ||
| balance = base.balance[request.recipient], | ||
| balances = base.balance | ||
| }) | ||
| end | ||
|
|
||
|
|
@@ -867,7 +884,7 @@ end | |
| --- We route any `action' to the appropriate function based on the request path. | ||
| function compute(base, assignment) | ||
| ao.event({ "compute called", | ||
| { balance = base.balance, ledgers = base.ledgers } }) | ||
| { balance = base.balance, ledgers = base.ledgers, action = assignment.body.action or "unknown" } }) | ||
|
|
||
| assignment.body.action = string.lower(assignment.body.action or "") | ||
|
|
||
|
|
@@ -880,6 +897,7 @@ function compute(base, assignment) | |
| elseif assignment.body.action == "register-remote" then | ||
| return _G["register-remote"](base, assignment) | ||
| else | ||
| ao.event({ "Unknown action received, initializing process." }) | ||
|
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. end improved hyper-token lua events |
||
| -- Handle unknown `action' values. | ||
| _, base = ensure_initialized(base, assignment) | ||
| base.results = { | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -557,7 +557,7 @@ validate_large_message_from_http_test() -> | |
|
|
||
| committed_id_test() -> | ||
| Msg = #{ <<"basic">> => <<"value">> }, | ||
| Signed = hb_message:commit(Msg, hb:wallet()), | ||
| Signed = hb_message:commit(Msg, #{ priv_wallet => hb:wallet() }), | ||
|
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. [test] Pass wallet as opt to hb_message:commit |
||
| ?assert(hb_message:verify(Signed, all, #{})), | ||
| ?event({signed_msg, Signed}), | ||
| UnsignedID = hb_message:id(Signed, none), | ||
|
|
@@ -599,8 +599,14 @@ commit_secret_key_test() -> | |
|
|
||
| multicommitted_id_test() -> | ||
| Msg = #{ <<"basic">> => <<"value">> }, | ||
| Signed1 = hb_message:commit(Msg, Wallet1 = ar_wallet:new()), | ||
| Signed2 = hb_message:commit(Signed1, Wallet2 = ar_wallet:new()), | ||
| Signed1 = hb_message:commit( | ||
| Msg, | ||
| #{ priv_wallet => Wallet1 = ar_wallet:new() } | ||
| ), | ||
| Signed2 = hb_message:commit( | ||
| Signed1, | ||
| #{ priv_wallet => Wallet2 = ar_wallet:new() } | ||
| ), | ||
| Addr1 = hb_util:human_id(ar_wallet:to_address(Wallet1)), | ||
| Addr2 = hb_util:human_id(ar_wallet:to_address(Wallet2)), | ||
| ?event({signed_msg, Signed2}), | ||
|
|
@@ -624,6 +630,6 @@ sign_and_verify_link_test() -> | |
| }, | ||
| NormMsg = hb_message:convert(Msg, <<"[email protected]">>, #{}), | ||
| ?event({msg, NormMsg}), | ||
| Signed = hb_message:commit(NormMsg, hb:wallet()), | ||
| Signed = hb_message:commit(NormMsg, #{ priv_wallet => hb:wallet() }), | ||
| ?event({signed_msg, Signed}), | ||
| ?assert(hb_message:verify(Signed)). | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -256,7 +256,7 @@ from_body_part(InlinedKey, Part, Opts) -> | |
| hb_maps:without( | ||
| [ | ||
| <<"content-disposition">>, | ||
| <<"content-type">>, | ||
| % <<"content-type">>, | ||
| <<"ao-body-key">>, | ||
| <<"content-digest">> | ||
| ], | ||
|
|
@@ -652,7 +652,7 @@ group_maps(Map, Parent, Top, Opts) when is_map(Map) -> | |
| end; | ||
| _ -> | ||
| ?event({group_maps, {norm_key, NormKey}, {value, Value}}), | ||
| case byte_size(Value) > ?MAX_HEADER_LENGTH of | ||
| case byte_size(hb_util:bin(Value)) > ?MAX_HEADER_LENGTH of | ||
|
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Cast value to bin if not already |
||
| % the value is too large to be encoded as a header | ||
| % within a part, so instead lift it to be a top level | ||
| % part | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
start. genesis_wasm -> genesis-wasm changes