Skip to content

Commit

Permalink
fixing a bug in if-then-else, adding test cases (#342)
Browse files Browse the repository at this point in the history
* adding simple setter-getter example for testing implementation of new

* adding an example that combines a bunch of things

* working towards fixing #340

* this may clear up #340, pushing to run against travis

* typo

* whitespace in test runner output

* whitespace in test files

* adding two tests. MultiLineIfRetSm.obs works now and shows me that the fixs
i made last friday in
38e8ec0
and
2aea8fc
at least don't break just by having more than one line in the if-block,
which is good.

MultiLineIfRet.obs does not work, per #341

* removing some comments, dead code

* inlining a simple function twice

* removing tabs and making the indentation uniform for obsidian files in ganache test

* updating file names

* fixing english langauge typo

* comments in tests
  • Loading branch information
ivoysey committed Jun 2, 2021
1 parent 0c8a5cc commit 2edd55e
Show file tree
Hide file tree
Showing 33 changed files with 250 additions and 147 deletions.
14 changes: 7 additions & 7 deletions resources/tests/GanacheTests/BoolLiteral.obs
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
main contract BoolLiteral{
transaction BoolLiteral () {
bool x;
x = true;
x = false;
}
transaction BoolLiteral () {
bool x;
x = true;
x = false;
}

transaction main() returns bool {
transaction main() returns bool {
return false;
}
}
}
8 changes: 8 additions & 0 deletions resources/tests/GanacheTests/CombinedBasics.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"gas" : 30000000000,
"gasprice" : "0x9184e72a000",
"startingeth" : 500000000,
"numaccts" : 1,
"testexp" : "main()",
"expected" : "24"
}
22 changes: 22 additions & 0 deletions resources/tests/GanacheTests/CombinedBasics.obs
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
/* this test combines the features of the other smaller tests that all come
* conceptually prior to structure types into one file, showing that they
* still work when they also interact.
*/

main contract CombinedBasics {
transaction val() returns int {
int x = 70;
if ( true && ! false ) {
x = 4 + 20;
} else {
x = 13;
}
return x;
}
transaction main() returns int{
int x;
x = 9 + 0;
x = val();
return x;
}
}
8 changes: 8 additions & 0 deletions resources/tests/GanacheTests/CombinedBasicsRet.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"gas" : 30000000000,
"gasprice" : "0x9184e72a000",
"startingeth" : 500000000,
"numaccts" : 1,
"testexp" : "main()",
"expected" : "24"
}
20 changes: 20 additions & 0 deletions resources/tests/GanacheTests/CombinedBasicsRet.obs
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
/* this test shows the same amount of compositionality of the simple
* language features as CombinedBasics, but also with multiple exit points
* from different branches of an if-then-else.
*/

main contract CombinedBasicsRet {
transaction val() returns int {
if ( true && ! false ) {
return 4 + 20;
} else {
return 13;
}
}
transaction main() returns int{
int x;
x = 9 + 0;
x = val();
return x;
}
}
24 changes: 12 additions & 12 deletions resources/tests/GanacheTests/If.obs
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
main contract If {
transaction iftest() {
int x;
if (true) {
x = 1;
}
return;
transaction iftest() {
int x;
if (true) {
x = 1;
}
return;
}

transaction main() returns int {
int x = 0;
if (true) {
x = 1;
}
return x;
transaction main() returns int {
int x = 0;
if (true) {
x = 1;
}
return x;
}
}
32 changes: 16 additions & 16 deletions resources/tests/GanacheTests/IfThenElse.obs
Original file line number Diff line number Diff line change
@@ -1,21 +1,21 @@
main contract IfThenElse {
transaction ifthenelse() {
int x;
if (true) {
x = 1;
} else {
x = 0;
}
return;
transaction ifthenelse() {
int x;
if (true) {
x = 1;
} else {
x = 0;
}
return;
}

transaction main() returns int {
int x = 9;
if (false) {
x = 50;
} else {
x = 90;
}
return x;
transaction main() returns int {
int x = 9;
if (false) {
x = 50;
} else {
x = 90;
}
return x;
}
}
16 changes: 8 additions & 8 deletions resources/tests/GanacheTests/IntConst.obs
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
main contract IntConst{
transaction intconst() {
int x;
x = 12;
return;
}
transaction intconst() {
int x;
x = 12;
return;
}

transaction main() returns int {
return 12;
}
transaction main() returns int {
return 12;
}
}
20 changes: 20 additions & 0 deletions resources/tests/GanacheTests/MultiLineIfRet.obs
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
main contract MultiLineIfRet {
transaction val() returns int {
int x = 0;
if ( true && ! false ) {
x = 4+20;
x = 11;
return 4 + x;
} else {
x = 13;
x = 90;
return 13;
}
}
transaction main() returns int{
int x;
x = 9 + 0;
x = val();
return x;
}
}
8 changes: 8 additions & 0 deletions resources/tests/GanacheTests/MultiLineIfRetSm.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"gas" : 30000000000,
"gasprice" : "0x9184e72a000",
"startingeth" : 500000000,
"numaccts" : 1,
"testexp" : "main()",
"expected" : "24"
}
23 changes: 23 additions & 0 deletions resources/tests/GanacheTests/MultiLineIfRetSm.obs
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
/* this test demonstrates that if-then-else blocks can have more than one
* line in them and still function correctly; it stops short of having much
* more than 1 line because of a limit on the number of stack
* variables. (https://github.com/mcoblenz/Obsidian/issues/341)
*/

main contract MultiLineIfRetSm {
transaction val() returns int {
int x = 0;
if ( true && ! false ) {
x = 20;
return 4 + x;
} else {
return 13;
}
}
transaction main() returns int{
int x;
x = 9 + 0;
x = val();
return x;
}
}
6 changes: 3 additions & 3 deletions resources/tests/GanacheTests/PrimOpsAdd.obs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
main contract PrimOpsAdd{
transaction primopsadd() returns int {
return(5+8);
}
transaction primopsadd() returns int {
return(5+8);
}
}
6 changes: 3 additions & 3 deletions resources/tests/GanacheTests/PrimOpsAnd.obs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
main contract PrimOpsAnd{
transaction primopsand() returns bool {
return(true && false);
}
transaction primopsand() returns bool {
return(true && false);
}
}
6 changes: 3 additions & 3 deletions resources/tests/GanacheTests/PrimOpsDiv.obs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
main contract PrimOpsDiv{
transaction primopsdiv() returns int {
return(4/2);
}
transaction primopsdiv() returns int {
return(4/2);
}
}
6 changes: 3 additions & 3 deletions resources/tests/GanacheTests/PrimOpsEq.obs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
main contract PrimOpsEq{
transaction primopseq() returns bool {
return(5 == 9);
}
transaction primopseq() returns bool {
return(5 == 9);
}
}
6 changes: 3 additions & 3 deletions resources/tests/GanacheTests/PrimOpsGreater.obs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
main contract PrimOpsGreater{
transaction primopsgreater() returns bool {
return(12 > 19);
}
transaction primopsgreater() returns bool {
return(12 > 19);
}
}
6 changes: 3 additions & 3 deletions resources/tests/GanacheTests/PrimOpsGreaterEq.obs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
main contract PrimOpsGreaterEq{
transaction primopsgreatereq() returns bool {
return(12 >= 12);
}
transaction primopsgreatereq() returns bool {
return(12 >= 12);
}
}
6 changes: 3 additions & 3 deletions resources/tests/GanacheTests/PrimOpsLess.obs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
main contract PrimOpsLess{
transaction primopsless() returns bool {
return(9 < 10);
}
transaction primopsless() returns bool {
return(9 < 10);
}
}
6 changes: 3 additions & 3 deletions resources/tests/GanacheTests/PrimOpsLessEq.obs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
main contract PrimOpsLessEq{
transaction primopslesseq() returns bool {
return(9 <= 19);
}
transaction primopslesseq() returns bool {
return(9 <= 19);
}
}
6 changes: 3 additions & 3 deletions resources/tests/GanacheTests/PrimOpsMod.obs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
main contract PrimOpsMod{
transaction primopsmod() returns int {
return(13 % 8);
}
transaction primopsmod() returns int {
return(13 % 8);
}
}
6 changes: 3 additions & 3 deletions resources/tests/GanacheTests/PrimOpsMul.obs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
main contract PrimOpsMul{
transaction primopsmul() returns int {
return(5*4);
}
transaction primopsmul() returns int {
return(5*4);
}
}
6 changes: 3 additions & 3 deletions resources/tests/GanacheTests/PrimOpsNEq.obs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
main contract PrimOpsNEq{
transaction primopsneq() returns bool {
return(5 != 9);
}
transaction primopsneq() returns bool {
return(5 != 9);
}
}
6 changes: 3 additions & 3 deletions resources/tests/GanacheTests/PrimOpsNeg.obs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
main contract PrimOpsNeg{
transaction primopsneg() returns int {
return(-20);
}
transaction primopsneg() returns int {
return(-20);
}
}
6 changes: 3 additions & 3 deletions resources/tests/GanacheTests/PrimOpsNotFalse.obs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
main contract PrimOpsNotFalse{
transaction primopsnotfalse() returns bool {
return(! false);
}
transaction primopsnotfalse() returns bool {
return(! false);
}
}
6 changes: 3 additions & 3 deletions resources/tests/GanacheTests/PrimOpsNotTrue.obs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
main contract PrimOpsNotTrue{
transaction primopsnottrue() returns bool {
return(! true);
}
transaction primopsnottrue() returns bool {
return(! true);
}
}
6 changes: 3 additions & 3 deletions resources/tests/GanacheTests/PrimOpsOr.obs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
main contract PrimOpsOr{
transaction primopsor() returns bool {
return(true || false);
}
transaction primopsor() returns bool {
return(true || false);
}
}
6 changes: 3 additions & 3 deletions resources/tests/GanacheTests/PrimOpsSubNeg.obs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
main contract PrimOpsSubNeg{
transaction primopssubneg() returns int {
return(5-20);
}
transaction primopssubneg() returns int {
return(5-20);
}
}
6 changes: 3 additions & 3 deletions resources/tests/GanacheTests/PrimOpsSubPos.obs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
main contract PrimOpsSubPos{
transaction primopssubpos() returns int {
return(20-5);
}
transaction primopssubpos() returns int {
return(20-5);
}
}
20 changes: 10 additions & 10 deletions resources/tests/GanacheTests/Return.obs
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
main contract Return {
transaction f() returns int{
return (4+4);
}
transaction g(){
int x = f();
return;
}
transaction f() returns int{
return (4+4);
}
transaction g(){
int x = f();
return;
}

transaction main() returns int{
return f();
}
transaction main() returns int{
return f();
}
}

0 comments on commit 2edd55e

Please sign in to comment.