functional_tests: expand script test

This commit is contained in:
Crypto City 2020-11-18 21:40:55 +00:00
parent 70420f0c3d
commit 203ecd44d6

View File

@ -4239,6 +4239,7 @@ class CCTest():
assert res.script == 1
assert res.script_state == 0
assert res.script_city == 0
assert res.script_owner == GAME_ACCOUNT
self.assert_exception(lambda: self.wallet[2].cc_script_choice(0, state = 0, city = 0, owner = GAME_ACCOUNT, choice = 0))
self.assert_exception(lambda: self.wallet[2].cc_script_choice(2, state = 0, city = 0, owner = GAME_ACCOUNT, choice = 0))
@ -4257,6 +4258,7 @@ class CCTest():
assert res.script == 1
assert res.script_state == 0
assert res.script_city == 0
assert res.script_owner == GAME_ACCOUNT
res = self.wallet[2].cc_script_choice(1, state = 0, city = 0, owner = GAME_ACCOUNT, choice = 1)
res = self.generate_blocks('TF1MMBg4zx18SnZC6oswCRB7DzdVeUKce5NdCMSWUHNY4wNvNhzmFj4WqZY2bFj8R1REAWR3qAH5zD7sjXyHz3tVayzHSswqymx', 1)
@ -4266,6 +4268,7 @@ class CCTest():
assert res.script == 1
assert res.script_state == 1
assert res.script_city == 0
assert res.script_owner == GAME_ACCOUNT
res = self.wallet[2].cc_script_choice(1, state = 1, city = 0, owner = GAME_ACCOUNT, choice = 1)
res = self.generate_blocks('TF1MMBg4zx18SnZC6oswCRB7DzdVeUKce5NdCMSWUHNY4wNvNhzmFj4WqZY2bFj8R1REAWR3qAH5zD7sjXyHz3tVayzHSswqymx', 1)
@ -4275,6 +4278,7 @@ class CCTest():
assert res.script == 1
assert res.script_state == 0
assert res.script_city == 0
assert res.script_owner == GAME_ACCOUNT
res = self.wallet[2].cc_script_choice(1, state = 0, city = 0, owner = GAME_ACCOUNT, choice = 1)
res = self.generate_blocks('TF1MMBg4zx18SnZC6oswCRB7DzdVeUKce5NdCMSWUHNY4wNvNhzmFj4WqZY2bFj8R1REAWR3qAH5zD7sjXyHz3tVayzHSswqymx', 1)
@ -4284,6 +4288,7 @@ class CCTest():
assert res.script == 1
assert res.script_state == 1
assert res.script_city == 0
assert res.script_owner == GAME_ACCOUNT
res = self.wallet[2].cc_script_choice(1, state = 1, city = 0, owner = GAME_ACCOUNT, choice = 0)
res = self.generate_blocks('TF1MMBg4zx18SnZC6oswCRB7DzdVeUKce5NdCMSWUHNY4wNvNhzmFj4WqZY2bFj8R1REAWR3qAH5zD7sjXyHz3tVayzHSswqymx', 1)
@ -4293,6 +4298,7 @@ class CCTest():
assert res.script == 1
assert res.script_state == 2
assert res.script_city == 0
assert res.script_owner == GAME_ACCOUNT
res = self.wallet[2].cc_script_choice(1, state = 2, city = 0, owner = GAME_ACCOUNT, choice = 1)
res = self.generate_blocks('TF1MMBg4zx18SnZC6oswCRB7DzdVeUKce5NdCMSWUHNY4wNvNhzmFj4WqZY2bFj8R1REAWR3qAH5zD7sjXyHz3tVayzHSswqymx', 1)
@ -4302,9 +4308,106 @@ class CCTest():
assert res.script == 0
assert res.script_state == 0
assert res.script_city == 0
assert res.script_owner == 0
self.assert_exception(lambda: self.wallet[2].cc_script_choice(1, state = 0, city = 0, owner = GAME_ACCOUNT, choice = 0))
print('testing looping script')
script = """
script {
name "looping state test"
precondition global "allow" == 1
reserves {
owner gold 0.002
player gold 0.001
}
state "0" {
choice { text "0" next state "0" actions { set local "tc" 0 award gold 0.00000001 + random 16} }
choice { text "1" next state "0" actions { set local "tc" 1 pay gold 0.00000002 set player "x" player "x" + 1} }
choice { text "2" next state "0" actions { set local "tc" 2 } }
choice { text "second" next state "1" actions { set global "loop-done" 2 + global "loop-done" } }
}
state "1" {
choice { text "0" next state "2" enabled local "ready" != 0 }
choice { text "1" next state "1" actions { set local "ready" 8 } }
}
state "2" {
choice { text "0" next state ""}
}
}
"""
self.wallet[3].cc_create_script(source = script)
res = self.generate_blocks('TF1MMBg4zx18SnZC6oswCRB7DzdVeUKce5NdCMSWUHNY4wNvNhzmFj4WqZY2bFj8R1REAWR3qAH5zD7sjXyHz3tVayzHSswqymx', 1)
res = daemon.cc_get_scripts(include_blob = True)
assert len(res.scripts) > 1
script_id = res.scripts[-1].index
# it should not be available yet
res = daemon.cc_get_scripts(first_script = script_id, last_script = script_id, account = account2_id)
assert len(res.scripts) == 1
assert not res.scripts[0].available
self.assert_exception(lambda: self.wallet[2].cc_start_script(script_id, city = 0))
res = self.wallet[3].cc_set_script_variable('allow', 0, 1)
res = self.generate_blocks('TF1MMBg4zx18SnZC6oswCRB7DzdVeUKce5NdCMSWUHNY4wNvNhzmFj4WqZY2bFj8R1REAWR3qAH5zD7sjXyHz3tVayzHSswqymx', 1)
# it should now be available yet
res = daemon.cc_get_scripts(first_script = script_id, last_script = script_id, account = account2_id)
assert len(res.scripts) == 1
assert res.scripts[0].available
# start the script
res = self.wallet[2].cc_start_script(script_id, city = 0)
res = self.generate_blocks('TF1MMBg4zx18SnZC6oswCRB7DzdVeUKce5NdCMSWUHNY4wNvNhzmFj4WqZY2bFj8R1REAWR3qAH5zD7sjXyHz3tVayzHSswqymx', 1)
res = daemon.cc_get_account(account2_id)
assert 'reserve' in res
assert res.script == script_id
assert res.script_state == 0
assert res.script_city == 0
assert res.script_owner == GAME_ACCOUNT
for i in [ 0, 1, 0, 2, 2, 1, 2, 2, 1, 0, 1, 0, 1, 1, 1, 2, 1, 0, 2, 1, 3]:
res = self.wallet[2].cc_script_choice(script_id, state = 0, city = 0, owner = GAME_ACCOUNT, choice = i)
res = self.generate_blocks('TF1MMBg4zx18SnZC6oswCRB7DzdVeUKce5NdCMSWUHNY4wNvNhzmFj4WqZY2bFj8R1REAWR3qAH5zD7sjXyHz3tVayzHSswqymx', 1)
res = daemon.cc_get_account(account2_id)
assert 'reserve' in res
assert res.script == script_id
assert res.script_city == 0
assert res.script_owner == GAME_ACCOUNT
if i == 3:
assert res.script_state == 1
assert len(res.script_local_variables) == 1
assert res.script_local_variables[0] == { 'name': 'tc', 'value': 1} # last before we changed state
else:
assert res.script_state == 0
if i == 0:
assert 'script_local_variables' not in res
else:
assert len(res.script_local_variables) == 1
assert res.script_local_variables[0] == { 'name': 'tc', 'value': i}
res = daemon.cc_get_script_variable('loop-done')
assert res.value == 2
res = daemon.cc_get_account(account2_id)
x = [x for x in res.script_variables if x.name == 'x'][0]
assert x.name == 'x'
assert x.value == 9
# we're in the second state now, we can't choose choice 0 until we chose choice 1
self.assert_exception(lambda: self.wallet[2].cc_script_choice(script_id, state = 1, city = 0, owner = GAME_ACCOUNT, choice = 0))
res = self.wallet[2].cc_script_choice(script_id, state = 1, city = 0, owner = GAME_ACCOUNT, choice = 1)
res = self.generate_blocks('TF1MMBg4zx18SnZC6oswCRB7DzdVeUKce5NdCMSWUHNY4wNvNhzmFj4WqZY2bFj8R1REAWR3qAH5zD7sjXyHz3tVayzHSswqymx', 1)
res = self.wallet[2].cc_script_choice(script_id, state = 1, city = 0, owner = GAME_ACCOUNT, choice = 0)
res = self.generate_blocks('TF1MMBg4zx18SnZC6oswCRB7DzdVeUKce5NdCMSWUHNY4wNvNhzmFj4WqZY2bFj8R1REAWR3qAH5zD7sjXyHz3tVayzHSswqymx', 1)
res = daemon.cc_get_account(account2_id)
assert res.script_state == 2
def check_item_count_consistency(self):
daemon = self.daemon