-
Notifications
You must be signed in to change notification settings - Fork 493
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
Ensure disassemble/reassemble cycle works in testProg. #2745
Changes from 1 commit
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 |
---|---|---|
|
@@ -1034,7 +1034,7 @@ func TestGlobal(t *testing.T) { | |
addr, err := basics.UnmarshalChecksumAddress(testAddr) | ||
require.NoError(t, err) | ||
ledger.creatorAddr = addr | ||
for v := uint64(0); v <= AssemblerMaxVersion; v++ { | ||
for v := uint64(1); v <= AssemblerMaxVersion; v++ { | ||
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. why is it changed to 1? 0 is used to be a valid version for TEAL 1 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 trouble is that when 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. I'm ok to have it set 1 here. The only problem this looks like the last place where assembling with version 0 happens. Probably a separate test checking assembling with version 0 at backwardCompat_test.go is needed 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. I don't see a good reason for |
||
_, ok := tests[v] | ||
require.True(t, ok) | ||
t.Run(fmt.Sprintf("v=%d", v), func(t *testing.T) { | ||
|
@@ -1055,9 +1055,6 @@ func TestGlobal(t *testing.T) { | |
txgroup := make([]transactions.SignedTxn, 1) | ||
txgroup[0] = txn | ||
sb := strings.Builder{} | ||
block := bookkeeping.Block{} | ||
block.BlockHeader.Round = 999999 | ||
block.BlockHeader.TimeStamp = 2069 | ||
proto := config.ConsensusParams{ | ||
MinTxnFee: 123, | ||
MinBalance: 1000000, | ||
|
@@ -2684,10 +2681,9 @@ func TestStackUnderflow(t *testing.T) { | |
t.Parallel() | ||
for v := uint64(1); v <= AssemblerMaxVersion; v++ { | ||
t.Run(fmt.Sprintf("v=%d", v), func(t *testing.T) { | ||
ops, err := AssembleStringWithVersion(`int 1`, v) | ||
ops := testProg(t, `int 1`, v) | ||
ops.Program = append(ops.Program, 0x08) // + | ||
require.NoError(t, err) | ||
err = Check(ops.Program, defaultEvalParams(nil, nil)) | ||
err := Check(ops.Program, defaultEvalParams(nil, nil)) | ||
require.NoError(t, err) | ||
sb := strings.Builder{} | ||
pass, err := Eval(ops.Program, defaultEvalParams(&sb, nil)) | ||
|
@@ -2707,10 +2703,9 @@ func TestWrongStackTypeRuntime(t *testing.T) { | |
t.Parallel() | ||
for v := uint64(1); v <= AssemblerMaxVersion; v++ { | ||
t.Run(fmt.Sprintf("v=%d", v), func(t *testing.T) { | ||
ops, err := AssembleStringWithVersion(`int 1`, v) | ||
require.NoError(t, err) | ||
ops := testProg(t, `int 1`, v) | ||
ops.Program = append(ops.Program, 0x01, 0x15) // sha256, len | ||
err = Check(ops.Program, defaultEvalParams(nil, nil)) | ||
err := Check(ops.Program, defaultEvalParams(nil, nil)) | ||
require.NoError(t, err) | ||
sb := strings.Builder{} | ||
pass, err := Eval(ops.Program, defaultEvalParams(&sb, nil)) | ||
|
@@ -2730,11 +2725,9 @@ func TestEqMismatch(t *testing.T) { | |
t.Parallel() | ||
for v := uint64(1); v <= AssemblerMaxVersion; v++ { | ||
t.Run(fmt.Sprintf("v=%d", v), func(t *testing.T) { | ||
ops, err := AssembleStringWithVersion(`byte 0x1234 | ||
int 1`, v) | ||
require.NoError(t, err) | ||
ops := testProg(t, `byte 0x1234; int 1`, v) | ||
ops.Program = append(ops.Program, 0x12) // == | ||
err = Check(ops.Program, defaultEvalParams(nil, nil)) | ||
err := Check(ops.Program, defaultEvalParams(nil, nil)) | ||
require.NoError(t, err) // TODO: Check should know the type stack was wrong | ||
sb := strings.Builder{} | ||
pass, err := Eval(ops.Program, defaultEvalParams(&sb, nil)) | ||
|
@@ -2754,11 +2747,9 @@ func TestNeqMismatch(t *testing.T) { | |
t.Parallel() | ||
for v := uint64(1); v <= AssemblerMaxVersion; v++ { | ||
t.Run(fmt.Sprintf("v=%d", v), func(t *testing.T) { | ||
ops, err := AssembleStringWithVersion(`byte 0x1234 | ||
int 1`, v) | ||
require.NoError(t, err) | ||
ops := testProg(t, `byte 0x1234; int 1`, v) | ||
ops.Program = append(ops.Program, 0x13) // != | ||
err = Check(ops.Program, defaultEvalParams(nil, nil)) | ||
err := Check(ops.Program, defaultEvalParams(nil, nil)) | ||
require.NoError(t, err) // TODO: Check should know the type stack was wrong | ||
sb := strings.Builder{} | ||
pass, err := Eval(ops.Program, defaultEvalParams(&sb, nil)) | ||
|
@@ -2778,11 +2769,9 @@ func TestWrongStackTypeRuntime2(t *testing.T) { | |
t.Parallel() | ||
for v := uint64(1); v <= AssemblerMaxVersion; v++ { | ||
t.Run(fmt.Sprintf("v=%d", v), func(t *testing.T) { | ||
ops, err := AssembleStringWithVersion(`byte 0x1234 | ||
int 1`, v) | ||
require.NoError(t, err) | ||
ops := testProg(t, `byte 0x1234; int 1`, v) | ||
ops.Program = append(ops.Program, 0x08) // + | ||
err = Check(ops.Program, defaultEvalParams(nil, nil)) | ||
err := Check(ops.Program, defaultEvalParams(nil, nil)) | ||
require.NoError(t, err) | ||
sb := strings.Builder{} | ||
pass, _ := Eval(ops.Program, defaultEvalParams(&sb, nil)) | ||
|
@@ -2802,15 +2791,14 @@ func TestIllegalOp(t *testing.T) { | |
t.Parallel() | ||
for v := uint64(1); v <= AssemblerMaxVersion; v++ { | ||
t.Run(fmt.Sprintf("v=%d", v), func(t *testing.T) { | ||
ops, err := AssembleStringWithVersion(`int 1`, v) | ||
require.NoError(t, err) | ||
ops := testProg(t, `int 1`, v) | ||
for opcode, spec := range opsByOpcode[v] { | ||
if spec.op == nil { | ||
ops.Program = append(ops.Program, byte(opcode)) | ||
break | ||
} | ||
} | ||
err = Check(ops.Program, defaultEvalParams(nil, nil)) | ||
err := Check(ops.Program, defaultEvalParams(nil, nil)) | ||
require.Error(t, err) | ||
sb := strings.Builder{} | ||
pass, err := Eval(ops.Program, defaultEvalParams(&sb, nil)) | ||
|
@@ -2830,15 +2818,14 @@ func TestShortProgram(t *testing.T) { | |
t.Parallel() | ||
for v := uint64(1); v <= AssemblerMaxVersion; v++ { | ||
t.Run(fmt.Sprintf("v=%d", v), func(t *testing.T) { | ||
ops, err := AssembleStringWithVersion(`int 1 | ||
ops := testProg(t, `int 1 | ||
bnz done | ||
done: | ||
int 1 | ||
`, v) | ||
require.NoError(t, err) | ||
// cut two last bytes - intc_1 and last byte of bnz | ||
ops.Program = ops.Program[:len(ops.Program)-2] | ||
err = Check(ops.Program, defaultEvalParams(nil, nil)) | ||
err := Check(ops.Program, defaultEvalParams(nil, nil)) | ||
require.Error(t, err) | ||
sb := strings.Builder{} | ||
pass, err := Eval(ops.Program, defaultEvalParams(&sb, nil)) | ||
|
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.
please add a comment for
rerun
, it is not obvious at allThere 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.
comment added