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
16 changes: 11 additions & 5 deletions data/transactions/logic/assembler.go
Original file line number Diff line number Diff line change
Expand Up @@ -472,13 +472,16 @@ func asmPushInt(ops *OpStream, spec *OpSpec, args []string) error {
return nil
}
func asmPushBytes(ops *OpStream, spec *OpSpec, args []string) error {
if len(args) != 1 {
return ops.errorf("%s needs one argument", spec.Name)
if len(args) == 0 {
return ops.errorf("%s operation needs byte literal argument", spec.Name)
}
val, _, err := parseBinaryArgs(args)
val, consumed, err := parseBinaryArgs(args)
if err != nil {
return ops.error(err)
}
if len(args) != consumed {
return ops.errorf("%s operation with extraneous argument", spec.Name)
}
ops.pending.WriteByte(spec.Opcode)
var scratch [binary.MaxVarintLen64]byte
vlen := binary.PutUvarint(scratch[:], uint64(len(val)))
Expand Down Expand Up @@ -636,12 +639,15 @@ func parseStringLiteral(input string) (result []byte, err error) {
// byte "this is a string\n"
func assembleByte(ops *OpStream, spec *OpSpec, args []string) error {
if len(args) == 0 {
return ops.error("byte operation needs byte literal argument")
return ops.errorf("%s operation needs byte literal argument", spec.Name)
}
val, _, err := parseBinaryArgs(args)
val, consumed, err := parseBinaryArgs(args)
if err != nil {
return ops.error(err)
}
if len(args) != consumed {
return ops.errorf("%s operation with extraneous argument", spec.Name)
}
ops.ByteLiteral(val)
return nil
}
Expand Down
24 changes: 23 additions & 1 deletion data/transactions/logic/assembler_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -475,6 +475,9 @@ func testProg(t testing.TB, source string, ver uint64, expected ...expect) *OpSt
require.NoError(t, err)
require.Equal(t, ops.Program, ops2.Program)
} else {
if err == nil {
t.Log(program)
}
require.Error(t, err)
errors := ops.Errors
for _, exp := range expected {
Expand Down Expand Up @@ -507,6 +510,7 @@ func testProg(t testing.TB, source string, ver uint64, expected ...expect) *OpSt
}

func testLine(t *testing.T, line string, ver uint64, expected string) {
t.Helper()
// By embedding the source line between two other lines, the
// test for the correct line number in the error is more
// meaningful.
Expand All @@ -517,6 +521,7 @@ func testLine(t *testing.T, line string, ver uint64, expected string) {
}
testProg(t, source, ver, expect{2, expected})
}

func TestAssembleTxna(t *testing.T) {
partitiontest.PartitionTest(t)

Expand Down Expand Up @@ -661,6 +666,7 @@ func TestAssembleBytes(t *testing.T) {
variations := []string{
"byte b32 MFRGGZDFMY",
"byte base32 MFRGGZDFMY",
"byte base32 MFRGGZDFMY",
"byte base32(MFRGGZDFMY)",
"byte b32(MFRGGZDFMY)",
"byte b32 MFRGGZDFMY======",
Expand All @@ -679,6 +685,11 @@ func TestAssembleBytes(t *testing.T) {
expectedDefaultConsts := "0126010661626364656628"
expectedOptimizedConsts := "018006616263646566"

bad := [][]string{
{"byte", "...operation needs byte literal argument"},
{`byte "john" "doe"`, "...operation with extraneous argument"},
}

for v := uint64(1); v <= AssemblerMaxVersion; v++ {
t.Run(fmt.Sprintf("v=%d", v), func(t *testing.T) {
expected := expectedDefaultConsts
Expand All @@ -690,8 +701,19 @@ func TestAssembleBytes(t *testing.T) {
ops := testProg(t, vi, v)
s := hex.EncodeToString(ops.Program)
require.Equal(t, mutateProgVersion(v, expected), s)
// pushbytes should take the same input
if v >= 3 {
testProg(t, strings.Replace(vi, "byte", "pushbytes", 1), v)
}
}

for _, b := range bad {
testProg(t, b[0], v, expect{1, b[1]})
// pushbytes should produce the same errors
if v >= 3 {
testProg(t, strings.Replace(b[0], "byte", "pushbytes", 1), v, expect{1, b[1]})
}
}
})
}
}
Expand Down Expand Up @@ -1448,7 +1470,7 @@ func TestConstantArgs(t *testing.T) {
}
for v := uint64(3); v <= AssemblerMaxVersion; v++ {
testProg(t, "pushint", v, expect{1, "pushint needs one argument"})
testProg(t, "pushbytes", v, expect{1, "pushbytes needs one argument"})
testProg(t, "pushbytes", v, expect{1, "pushbytes operation needs byte literal argument"})
}

}
Expand Down
3 changes: 0 additions & 3 deletions data/transactions/teal.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,6 @@ type EvalDelta struct {

Logs []string `codec:"lg,allocbound=config.MaxLogCalls"`

// Intentionally, temporarily wrong - need to decide how to
// allocbound properly when structure is recursive. Even a bound
// of 2 would allow arbitrarily large object if deep.
InnerTxns []SignedTxnWithAD `codec:"itx,allocbound=config.MaxInnerTransactions"`
}

Expand Down