Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 6 additions & 3 deletions transaction.go
Original file line number Diff line number Diff line change
Expand Up @@ -416,9 +416,12 @@ func (t *Transaction) payloadCanonicalForm() payloadCanonicalForm {
}

// note(sideninja): This is a temporary workaround until cadence defines canonical format addressing the issue https://github.com/onflow/flow-go-sdk/issues/286
for i, arg := range t.Arguments {
if len(arg) > 0 && arg[len(arg)-1] == byte(10) { // extra new line character
t.Arguments[i] = arg[:len(arg)-1]
// system transactions (Payer == EmptyAddress) preserve trailing newlines in arguments
if t.Payer != EmptyAddress {
for i, arg := range t.Arguments {
if len(arg) > 0 && arg[len(arg)-1] == byte(10) { // extra new line character
t.Arguments[i] = arg[:len(arg)-1]
}
}
}

Expand Down
24 changes: 24 additions & 0 deletions transaction_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -745,6 +745,15 @@ func baseTx() *flow.Transaction {
AddPayloadSignature(flow.HexToAddress("01"), 4, sig)
}

func baseSystemTx() *flow.Transaction {
return flow.NewTransaction().
SetScript([]byte(`transaction { execute { log("Hello, World!") } }`)).
SetReferenceBlockID(flow.HexToID("f0e4c2f76c58916ec258f246851bea091d14d4247a2fc3e18694461b1816e13b")).
SetComputeLimit(42).
SetProposalKey(flow.HexToAddress("01"), 4, 10).
AddAuthorizer(flow.HexToAddress("02"))
}

func copyTxPayload(tx *flow.Transaction) *flow.Transaction {
return &flow.Transaction{
Script: tx.Script,
Expand Down Expand Up @@ -835,6 +844,21 @@ func TestTransaction_RLPMessages(t *testing.T) {
payload: "f8afb07472616e73616374696f6e207b2065786563757465207b206c6f67282248656c6c6f2c20576f726c64212229207d207df83c9f7b2276616c7565223a22666f6f222c2274797065223a22537472696e67227d9b7b2276616c7565223a223432222c2274797065223a22496e74227da0f0e4c2f76c58916ec258f246851bea091d14d4247a2fc3e18694461b1816e13b2a880000000000000001040a880000000000000001c9880000000000000001",
envelope: "f8d6f8afb07472616e73616374696f6e207b2065786563757465207b206c6f67282248656c6c6f2c20576f726c64212229207d207df83c9f7b2276616c7565223a22666f6f222c2274797065223a22537472696e67227d9b7b2276616c7565223a223432222c2274797065223a22496e74227da0f0e4c2f76c58916ec258f246851bea091d14d4247a2fc3e18694461b1816e13b2a880000000000000001040a880000000000000001c9880000000000000001e4e38004a0f7225388c1d69d57e6251c9fda50cbbf9e05131e5adb81e5aa0422402f048162",
},
{
// System transactions (Payer == EmptyAddress) preserve trailing newlines in arguments.
name: "System transaction with single argument",
tx: baseSystemTx().AddRawArgument(jsoncdc.MustEncode(cadence.String("foo"))),
payload: "f893b07472616e73616374696f6e207b2065786563757465207b206c6f67282248656c6c6f2c20576f726c64212229207d207de1a07b2276616c7565223a22666f6f222c2274797065223a22537472696e67227d0aa0f0e4c2f76c58916ec258f246851bea091d14d4247a2fc3e18694461b1816e13b2a880000000000000001040a880000000000000000c9880000000000000002",
envelope: "f896f893b07472616e73616374696f6e207b2065786563757465207b206c6f67282248656c6c6f2c20576f726c64212229207d207de1a07b2276616c7565223a22666f6f222c2274797065223a22537472696e67227d0aa0f0e4c2f76c58916ec258f246851bea091d14d4247a2fc3e18694461b1816e13b2a880000000000000001040a880000000000000000c9880000000000000002c0",
},
{
name: "System transaction with multiple arguments",
tx: baseSystemTx().
AddRawArgument(jsoncdc.MustEncode(cadence.String("foo"))).
AddRawArgument(jsoncdc.MustEncode(cadence.NewInt(42))),
payload: "f8b1b07472616e73616374696f6e207b2065786563757465207b206c6f67282248656c6c6f2c20576f726c64212229207d207df83ea07b2276616c7565223a22666f6f222c2274797065223a22537472696e67227d0a9c7b2276616c7565223a223432222c2274797065223a22496e74227d0aa0f0e4c2f76c58916ec258f246851bea091d14d4247a2fc3e18694461b1816e13b2a880000000000000001040a880000000000000000c9880000000000000002",
envelope: "f8b4f8b1b07472616e73616374696f6e207b2065786563757465207b206c6f67282248656c6c6f2c20576f726c64212229207d207df83ea07b2276616c7565223a22666f6f222c2274797065223a22537472696e67227d0a9c7b2276616c7565223a223432222c2274797065223a22496e74227d0aa0f0e4c2f76c58916ec258f246851bea091d14d4247a2fc3e18694461b1816e13b2a880000000000000001040a880000000000000000c9880000000000000002c0",
},
}

for _, tt := range tests {
Expand Down
Loading