Skip to content

Commit

Permalink
Merge pull request #180 from Pylons-tech/cel_type_conversion_unit_tes…
Browse files Browse the repository at this point in the history
…t_and_doc

fixture test for coinoutput with input and unit test for mix of randi, int, double function
  • Loading branch information
antstalepresh authored Mar 6, 2020
2 parents 3165522 + a5df985 commit fbabcd7
Show file tree
Hide file tree
Showing 6 changed files with 120 additions and 0 deletions.
5 changes: 5 additions & 0 deletions cmd/fixtures_test/executions/hlg_coin_program_with_input.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"RecipeName":"Helicopter's Hlg Coin Generation From Input Recipe",
"Sender":"michael",
"ItemNames":["Helicopter's Knife lv3"]
}
7 changes: 7 additions & 0 deletions cmd/fixtures_test/items/heli_knife_lv3.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"Doubles": [{ "Key": "attack", "Value": "3" }],
"Longs": [{ "Key": "level", "Value": "3" }],
"Strings": [{ "Key": "Name", "Value": "Helicopter's Knife lv3" }],
"CookbookName": "helicopter",
"Sender": "michael"
}
23 changes: 23 additions & 0 deletions cmd/fixtures_test/recipes/hlg_coin_program_with_input.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
{
"RType": "0",
"CoinInputs":[],
"ItemInputRefs": [
"./recipes/item_input/heli_knife_lv3.json"
],
"Entries":{
"CoinOutputs":[
{
"Coin": "hlgcoin",
"Program": "int(attack * double(5))",
"Weight": 1
}
],
"ItemOutputs":[]
},
"ExtraInfo":"",
"Sender":"eugen",
"Name": "Helicopter's Hlg Coin Generation From Input Recipe",
"CookbookName": "helicopter",
"Description": "this has to meet character limits lol",
"BlockInterval":"0"
}
5 changes: 5 additions & 0 deletions cmd/fixtures_test/recipes/item_input/heli_knife_lv3.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"Doubles": [{"Key": "attack", "MinValue": "3", "MaxValue": "3"}],
"Longs": [{"Key": "level", "MinValue": "3", "MaxValue": "3"}],
"Strings": [{"Key": "Name", "Value": "Helicopter's Knife lv3"}]
}
73 changes: 73 additions & 0 deletions cmd/fixtures_test/scenarios/helicopter.json
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,30 @@
]
}
},
{
"ID": "CREATE_HELI_KNIFE_LV3",
"runAfter": {
"precondition": ["CREATE_HELICOPTER_COOKBOOK"],
"blockWait": 0
},
"action": "fiat_item",
"paramsRef": "./items/heli_knife_lv3.json",
"output": {
"txResult": {
"status": "Success"
},
"property": [
{
"owner": "michael",
"items": [
{
"stringValues": { "Name": "Helicopter's Knife lv3" }
}
]
}
]
}
},
{
"ID": "CREATE_HELI_SHIELD_LV1",
"runAfter": {
Expand Down Expand Up @@ -299,6 +323,26 @@
]
}
},
{
"ID": "CREATE_HLG_COIN_PROGRAM_WITH_INPUT_RECIPE",
"runAfter": {
"precondition": ["CREATE_HELICOPTER_COOKBOOK"],
"blockWait": 0
},
"action": "create_recipe",
"paramsRef": "./recipes/hlg_coin_program_with_input.json",
"output": {
"txResult": {
"status": "Success"
},
"property": [
{
"owner": "eugen",
"recipes": ["Helicopter's Hlg Coin Generation From Input Recipe"]
}
]
}
},
{
"ID": "EXECUTE_HELI_STRAIGHT_ATTACK_KNIFE_RECIPE",
"runAfter": {
Expand Down Expand Up @@ -527,5 +571,34 @@
},
"property": []
}
},
{
"ID": "EXECUTE_HLG_COIN_PROGRAM_WITH_INPUT_RECIPE",
"runAfter": {
"precondition": [
"CREATE_HELI_KNIFE_LV3",
"CREATE_HLG_COIN_PROGRAM_WITH_INPUT_RECIPE"
],
"blockWait": 0
},
"action": "execute_recipe",
"paramsRef": "./executions/hlg_coin_program_with_input.json",
"output": {
"txResult": {
"status": "Success",
"message": "successfully executed the recipe"
},
"property": [
{
"owner": "michael",
"coins": [
{
"denom": "hlgcoin",
"amount": 15
}
]
}
]
}
}
]
7 changes: 7 additions & 0 deletions x/pylons/types/program_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,13 @@ func TestProgramWorkAsExpected(t *testing.T) {
require.True(t, out.Value().(string) == "2.5")
require.True(t, err == nil)

// randi, double, multiply and int merge test
out, err = CheckAndExecuteProgram(env, variables, funcs, `int(5.0 * double(randi(2)+4) )`)
t.Log(`int(5.0 * double(randi(2)+4) )`, out, err)
val64 = out.Value().(int64)
require.True(t, val64 == 20 || val64 == 25 || val64 == 30)
require.True(t, err == nil)

// failing test
out, err = CheckAndExecuteProgram(env, variables, funcs, `level + attack`)
t.Log(`level + attack`, out, err)
Expand Down

0 comments on commit fbabcd7

Please sign in to comment.