github.com/aergoio/aergo@v1.3.1/contract/sqlcheck_test.go (about)

     1  package contract
     2  
     3  import "testing"
     4  
     5  var testCases = map[string][2]bool{
     6  	"PRAGMA index_info('idx52')":                                  {true, true},
     7  	"/* PRAGMA */ insert into t values (1, 2)":                    {true, false},
     8  	"insert /* PRAGMA */ into t values (1, 2)":                    {true, false},
     9  	"insert/* PRAGMA */ into t values (1, 2)":                     {true, false},
    10  	"/* pragma insert into t values (1, 2) */":                    {false, false},
    11  	"-- pragma insert into t values (1, 2)":                       {false, false},
    12  	"attach database test as \"test\"":                            {false, false},
    13  	"attach*database test as \"test\"":                            {false, false},
    14  	"'insert' into t values (1, 2)":                               {false, false},
    15  	"select into t values (1, 2)":                                 {true, true},
    16  	"create table t (a bigint, b text)":                           {true, false},
    17  	"/* asdfasdf\n asdfadsf */ create table t (a bigint, b text)": {true, false},
    18  	"-- asdfasdf\n asdfadsf create table t (a bigint, b text)":    {false, false},
    19  	"-- asdfasdf\n create table t (a bigint, b text)":             {true, false},
    20  	"insert\n-- asdfasdf\n create table t (a bigint, b text)":     {true, false},
    21  	"create trigger x ...":                                        {false, false},
    22  	"create view v ...":                                           {false, false},
    23  	"create temp table tt ...":                                    {false, false},
    24  	"create index":                                                {true, false},
    25  	"/* blah -- blah ... */ create index":                         {true, false},
    26  }
    27  
    28  func TestIsPermittedSql(t *testing.T) {
    29  	for s, r := range testCases {
    30  		expected := r[0]
    31  		t.Log(s, expected)
    32  		if cPermittedSql(s) != expected {
    33  			t.Errorf("[FAIL] %s, expected: %v, got: %v\n", s, expected, !expected)
    34  		}
    35  	}
    36  }
    37  func TestIsReadOnlySql(t *testing.T) {
    38  	for s, r := range testCases {
    39  		expected := r[1]
    40  		t.Log(s, expected)
    41  		if cReadOnlySql(s) != expected {
    42  			t.Errorf("[FAIL] %s, expected: %v, got: %v\n", s, expected, !expected)
    43  		}
    44  	}
    45  }