github.com/Tri-stone/burrow@v0.25.0/vent/test/sqlsol.go (about)

     1  package test
     2  
     3  import (
     4  	"testing"
     5  )
     6  
     7  // GoodJSONConfFile sets a good json file to be used in projection tests
     8  func GoodJSONConfFile(t *testing.T) string {
     9  	t.Helper()
    10  
    11  	goodJSONConfFile := `[
    12  		{
    13  			"TableName" : "UserAccounts",
    14  			"Filter" : "LOG0 = 'UserAccounts'",
    15  			"DeleteMarkerField": "__DELETE__",
    16  			"FieldMappings"  : [
    17  				{"Field": "userAddress" , "ColumnName" : "address", "Type": "address", "Primary" : true},
    18  				{"Field": "userName", "ColumnName" : "username", "Type": "string", "Primary" : false},
    19  				{"Field": "userId", "ColumnName" : "userid", "Type": "uint256", "Primary" : false},
    20  				{"Field": "userBool", "ColumnName" : "userbool", "Type": "bool", "Primary" : false}
    21  			]
    22  		},
    23  		{
    24  		"TableName" : "TEST_TABLE",
    25  		"Filter" : "Log1Text = 'EVENT_TEST'",
    26  		"DeleteMarkerField": "__DELETE__",
    27  		"FieldMappings"  : [
    28  			{"Field": "key", "ColumnName": "Index",    "Type": "uint256", "Primary" : true},
    29  			{"Field": "blocknum", "ColumnName": "Block",    "Type": "uint256", "Primary" : false},
    30  			{"Field": "somestr", "ColumnName": "String",   "Type": "string", "Primary" : false},
    31  			{"Field": "instance", "ColumnName": "Instance", "Type": "uint", "Primary" : false}
    32  		]
    33  	}
    34  	]`
    35  
    36  	return goodJSONConfFile
    37  }
    38  
    39  // MissingFieldsJSONConfFile sets a json file with missing fields to be used in projection tests
    40  func MissingFieldsJSONConfFile(t *testing.T) string {
    41  	t.Helper()
    42  
    43  	missingFieldsJSONConfFile := `[
    44  		{
    45  			"TableName" : "UserAccounts",
    46  			"Fields"  , 
    47  				"userAddress" , "ColumnName" : "address", "Primary" : true},
    48  				"userName", "ColumnName" : "username", "Primary" : false}
    49  			}
    50  		}
    51  	]`
    52  
    53  	return missingFieldsJSONConfFile
    54  }
    55  
    56  // UnknownTypeJSONConfFile sets a json file with unknown column types to be used in projection tests
    57  func UnknownTypeJSONConfFile(t *testing.T) string {
    58  	t.Helper()
    59  
    60  	unknownTypeJSONConfFile := `[
    61  		{
    62  			"TableName" : "UserAccounts",
    63  			"Filter" : "LOG0 = 'UserAccounts'",
    64  			"DeleteMarkerField": "__DELETE__",
    65  			"Event"  , 
    66  				"anonymous": false,
    67  				"inputs": [{
    68  					"indexed": false,
    69  					"ColumnName": "userName",
    70  					"Type": "typeunknown"
    71  				}, {
    72  					"indexed": false,
    73  					"ColumnName": "userAddress",
    74  					"Type": "address"
    75  				}, {
    76  					"indexed": false,
    77  					"ColumnName": "UnimportantInfo",
    78  					"Type": "uint"
    79  				}],
    80  				"ColumnName": "UpdateUserAccount",
    81  				"Type": "event"
    82  			},
    83  			"Fields"  , 
    84  				"userAddress" , "ColumnName" : "address", "Primary" : true},
    85  				"userName", "ColumnName" : "username", "Primary" : false}
    86  			}
    87  		},
    88  		{
    89  			"TableName" : "EventTest",
    90  			"Filter" : "LOG0 = 'EventTest'",
    91  			"DeleteMarkerField": "__DELETE__",
    92  			"Event"  , 
    93  				"anonymous": false,
    94  				"inputs": [{
    95  					"indexed": false,
    96  					"ColumnName": "ColumnName",
    97  					"Type": "typeunknown"
    98  				}, {
    99  					"indexed": false,
   100  					"ColumnName": "description",
   101  					"Type": "string"
   102  				}, {
   103  					"indexed": false,
   104  					"ColumnName": "UnimportantInfo",
   105  					"Type": "uint"
   106  				}],
   107  				"ColumnName": "TEST_EVENTS",
   108  				"Type": "event"
   109  			},
   110  			"Fields"  , 
   111  				"ColumnName" , "ColumnName" : "testname", "Primary" : true},
   112  				"description", "ColumnName" : "testdescription", "Primary" : false}
   113  			}
   114  		}
   115  	]`
   116  
   117  	return unknownTypeJSONConfFile
   118  }
   119  
   120  // BadJSONConfFile sets a malformed json file to be used in projection tests
   121  func BadJSONConfFile(t *testing.T) string {
   122  	t.Helper()
   123  
   124  	badJSONConfFile := `[
   125  		{
   126  			"TableName" : "UserAccounts",
   127  			"Event"  , 
   128  				"anonymous": false,
   129  				"inputs": [{
   130  					"indexed": false,
   131  					"ColumnName": "userName",
   132  					"Type": "string"
   133  				}, {
   134  					"indexed": false,
   135  					"ColumnName": "userAddress",
   136  					"Type": "address"
   137  				}, {
   138  					"indexed": false,
   139  					"ColumnName": "UnimportantInfo",
   140  					"Type": "uint"
   141  				}],
   142  				"ColumnName": "UpdateUserAccount",
   143  			},
   144  			"Fields"  , 
   145  				"userAddress" , "ColumnName" : "address", "Primary" : true},
   146  				"userName", "ColumnName" : "username", "Primary" : false}
   147  	]`
   148  
   149  	return badJSONConfFile
   150  }
   151  
   152  // DuplicatedColNameJSONConfFile sets a good json file but with duplicated column names for a given table
   153  func DuplicatedColNameJSONConfFile(t *testing.T) string {
   154  	t.Helper()
   155  
   156  	duplicatedColNameJSONConfFile := `[
   157  		{
   158  			"TableName" : "DUPLICATED_COLUMN",
   159  			"Filter" : "LOG0 = 'UserAccounts'",
   160  			"DeleteMarkerField": "__DELETE__",
   161  			"Fields"  , 
   162  				"userAddress" , "ColumnName" : "address", "Primary" : true},
   163  				"userName", "ColumnName" : "duplicated", "Primary" : false},
   164  				"userId", "ColumnName" : "userid", "Primary" : false},
   165  				"userBool", "ColumnName" : "duplicated", "Primary" : false}
   166  			}
   167  	}
   168  	]`
   169  
   170  	return duplicatedColNameJSONConfFile
   171  }