-
Notifications
You must be signed in to change notification settings - Fork 536
Opcode: log #2529
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
Opcode: log #2529
Changes from 44 commits
52254a4
1f5f64e
dc2ee1b
a8fab5b
3196118
7f261cc
1e427c1
47a9b74
0806abb
366d0a8
68ca45c
5a595a5
f9e61e2
341858b
fc7ce6d
fadac7d
ef0b8b5
8a17098
40aa921
d9ac639
7df07f6
0ef27a6
467b0c7
18a4351
fb9ec97
034386a
3eb6259
15bbe45
e40a33a
2dcb4a5
f618c22
198b1dd
ad49cab
1085f4f
79b870b
b18e435
1e8ef62
7c286bc
c88dfae
4fb6e4e
eb3ace4
023c440
bb65c70
c9504e1
a86db27
f375213
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 | ||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -346,7 +346,7 @@ func init() { | |||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||
| // legder requires proto string and proto params set | ||||||||||||||||||||||||||||
| var proto config.ConsensusParams | ||||||||||||||||||||||||||||
| proto.LogicSigVersion = 4 | ||||||||||||||||||||||||||||
| proto.LogicSigVersion = 5 | ||||||||||||||||||||||||||||
| proto.LogicSigMaxCost = 20000 | ||||||||||||||||||||||||||||
| proto.MaxAppProgramCost = 700 | ||||||||||||||||||||||||||||
| proto.MaxAppKeyLen = 64 | ||||||||||||||||||||||||||||
|
|
@@ -1091,3 +1091,113 @@ int 1`) | |||||||||||||||||||||||||||
| logResponse(t, &response) | ||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||
| func TestDryrunLogs(t *testing.T) { | ||||||||||||||||||||||||||||
|
jasonpaulos marked this conversation as resolved.
|
||||||||||||||||||||||||||||
| t.Parallel() | ||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||
| ops, err := logic.AssembleString(` | ||||||||||||||||||||||||||||
| #pragma version 5 | ||||||||||||||||||||||||||||
| byte "A" | ||||||||||||||||||||||||||||
| loop: | ||||||||||||||||||||||||||||
| int 0 | ||||||||||||||||||||||||||||
| dup2 | ||||||||||||||||||||||||||||
| getbyte | ||||||||||||||||||||||||||||
| int 1 | ||||||||||||||||||||||||||||
| + | ||||||||||||||||||||||||||||
| dup | ||||||||||||||||||||||||||||
| int 97 //ascii code of last char | ||||||||||||||||||||||||||||
| <= | ||||||||||||||||||||||||||||
| bz end | ||||||||||||||||||||||||||||
| setbyte | ||||||||||||||||||||||||||||
| dup | ||||||||||||||||||||||||||||
| log | ||||||||||||||||||||||||||||
| b loop | ||||||||||||||||||||||||||||
| end: | ||||||||||||||||||||||||||||
| int 1 | ||||||||||||||||||||||||||||
| return | ||||||||||||||||||||||||||||
| `) | ||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||
| require.NoError(t, err) | ||||||||||||||||||||||||||||
| approval := ops.Program | ||||||||||||||||||||||||||||
| ops, err = logic.AssembleString("int 1") | ||||||||||||||||||||||||||||
| clst := ops.Program | ||||||||||||||||||||||||||||
| ops, err = logic.AssembleString("#pragma version 5 \nint 1") | ||||||||||||||||||||||||||||
|
algorandskiy marked this conversation as resolved.
|
||||||||||||||||||||||||||||
| approv := ops.Program | ||||||||||||||||||||||||||||
| require.NoError(t, err) | ||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||
| var appIdx basics.AppIndex = 1 | ||||||||||||||||||||||||||||
| creator := randomAddress() | ||||||||||||||||||||||||||||
| sender := randomAddress() | ||||||||||||||||||||||||||||
| dr := DryrunRequest{ | ||||||||||||||||||||||||||||
| Txns: []transactions.SignedTxn{ | ||||||||||||||||||||||||||||
| { | ||||||||||||||||||||||||||||
| Txn: transactions.Transaction{ | ||||||||||||||||||||||||||||
| Header: transactions.Header{Sender: sender}, | ||||||||||||||||||||||||||||
| Type: protocol.ApplicationCallTx, | ||||||||||||||||||||||||||||
| ApplicationCallTxnFields: transactions.ApplicationCallTxnFields{ | ||||||||||||||||||||||||||||
| ApplicationID: appIdx, | ||||||||||||||||||||||||||||
| OnCompletion: transactions.OptInOC, | ||||||||||||||||||||||||||||
| }, | ||||||||||||||||||||||||||||
| }, | ||||||||||||||||||||||||||||
| }, | ||||||||||||||||||||||||||||
| { | ||||||||||||||||||||||||||||
| Txn: transactions.Transaction{ | ||||||||||||||||||||||||||||
| Header: transactions.Header{Sender: sender}, | ||||||||||||||||||||||||||||
| Type: protocol.ApplicationCallTx, | ||||||||||||||||||||||||||||
| ApplicationCallTxnFields: transactions.ApplicationCallTxnFields{ | ||||||||||||||||||||||||||||
| ApplicationID: appIdx + 1, | ||||||||||||||||||||||||||||
| OnCompletion: transactions.OptInOC, | ||||||||||||||||||||||||||||
| }, | ||||||||||||||||||||||||||||
| }, | ||||||||||||||||||||||||||||
| }, | ||||||||||||||||||||||||||||
| }, | ||||||||||||||||||||||||||||
| Apps: []generated.Application{ | ||||||||||||||||||||||||||||
| { | ||||||||||||||||||||||||||||
| Id: uint64(appIdx), | ||||||||||||||||||||||||||||
| Params: generated.ApplicationParams{ | ||||||||||||||||||||||||||||
| Creator: creator.String(), | ||||||||||||||||||||||||||||
| ApprovalProgram: approval, | ||||||||||||||||||||||||||||
| ClearStateProgram: clst, | ||||||||||||||||||||||||||||
| LocalStateSchema: &generated.ApplicationStateSchema{NumByteSlice: 1}, | ||||||||||||||||||||||||||||
| }, | ||||||||||||||||||||||||||||
| }, | ||||||||||||||||||||||||||||
| { | ||||||||||||||||||||||||||||
| Id: uint64(appIdx + 1), | ||||||||||||||||||||||||||||
| Params: generated.ApplicationParams{ | ||||||||||||||||||||||||||||
| Creator: creator.String(), | ||||||||||||||||||||||||||||
| ApprovalProgram: approv, | ||||||||||||||||||||||||||||
| ClearStateProgram: clst, | ||||||||||||||||||||||||||||
| LocalStateSchema: &generated.ApplicationStateSchema{NumByteSlice: 1}, | ||||||||||||||||||||||||||||
| }, | ||||||||||||||||||||||||||||
| }, | ||||||||||||||||||||||||||||
| }, | ||||||||||||||||||||||||||||
| Accounts: []generated.Account{ | ||||||||||||||||||||||||||||
| { | ||||||||||||||||||||||||||||
| Address: sender.String(), | ||||||||||||||||||||||||||||
| Status: "Online", | ||||||||||||||||||||||||||||
| Amount: 10000000, | ||||||||||||||||||||||||||||
| }, | ||||||||||||||||||||||||||||
| }, | ||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||
| dr.ProtocolVersion = string(dryrunProtoVersion) | ||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||
| var response generated.DryrunResponse | ||||||||||||||||||||||||||||
| doDryrunRequest(&dr, &response) | ||||||||||||||||||||||||||||
| require.NoError(t, err) | ||||||||||||||||||||||||||||
| checkAppCallPass(t, &response) | ||||||||||||||||||||||||||||
| if t.Failed() { | ||||||||||||||||||||||||||||
| logResponse(t, &response) | ||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||
| logs := *response.Txns[0].Logs | ||||||||||||||||||||||||||||
| assert.Equal(t, 32, len(logs)) | ||||||||||||||||||||||||||||
| for i, m := range logs { | ||||||||||||||||||||||||||||
| assert.Equal(t, base64.StdEncoding.EncodeToString([]byte(string(rune('B'+i)))), m.Value) | ||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||
|
Comment on lines
+1182
to
+1195
Contributor
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. Calculating values looks more maintainable, check below:
Suggested change
If logs are not sorted, use sort.Slice. If logs is map (not sure) then flatten it: type flog struct {
idx int,
li LogItem
}
for k, v := range logs {
flatlog = append(flatlog, flog{i, v})
}
sort.Slice(flatlog, func(i, j int) {return flatlog[i].idx < flatlog[j].idx})
Contributor
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. The order of logs matter, so they should not be sorted before comparison
Contributor
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. well ok, then |
||||||||||||||||||||||||||||
| encoded := string(protocol.EncodeJSON(response.Txns[0])) | ||||||||||||||||||||||||||||
| assert.Contains(t, encoded, "logs") | ||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||
| assert.Empty(t, response.Txns[1].Logs) | ||||||||||||||||||||||||||||
| encoded = string(protocol.EncodeJSON(response.Txns[1])) | ||||||||||||||||||||||||||||
| assert.NotContains(t, encoded, "logs") | ||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||
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.