-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #124 from ltonetwork/fix-smart-account
Fix smart account
- Loading branch information
Showing
73 changed files
with
364 additions
and
121 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
Feature: Smart account | ||
|
||
Background: Anchor setup | ||
Given Alice has an account with 100 lto | ||
Given Bob has a new account | ||
Given Charlie has a new account | ||
|
||
Scenario: Create smart account | ||
When Alice creates a smart account with script | ||
""" | ||
sigVerify(tx.bodyBytes, tx.proofs[0], tx.senderPublicKey) | ||
""" | ||
Then Alice has a smart account | ||
And Alice has 95 lto | ||
|
||
|
||
Scenario: Clear smart account | ||
Given Alice has a smart account with script | ||
""" | ||
sigVerify(tx.bodyBytes, tx.proofs[0], tx.senderPublicKey) | ||
""" | ||
When Alice removes the account script | ||
Then Alice doesn't have a smart account | ||
And Alice has 95 lto | ||
|
||
Scenario: Modify smart account | ||
Given Alice has a smart account with script | ||
""" | ||
sigVerify(tx.bodyBytes, tx.proofs[0], tx.senderPublicKey) | ||
""" | ||
When Alice creates a smart account with script | ||
""" | ||
true | ||
""" | ||
Then Alice has a smart account | ||
And Alice has 95 lto | ||
|
||
Scenario: Transactions with smart account | ||
Given Alice has a smart account with script | ||
""" | ||
sigVerify(tx.bodyBytes, tx.proofs[0], tx.senderPublicKey) | ||
""" | ||
When Alice transfers 10 LTO to Bob | ||
And Alice does a mass-transfer of 2 lto to Bob and 1 lto to Charlie | ||
And Alice issues an association with Bob of type 1 | ||
And Alice revokes the association with Bob of type 1 | ||
And Alice sets data "foo" to "bar" | ||
And Alice leases 10 lto to Bob | ||
And Alice cancels the lease to Bob | ||
And Alice sponsors Bob | ||
And Alice cancels the sponsorship for Bob | ||
And Alice registers an account | ||
|
||
Scenario: Restricted account | ||
Given Alice has a smart account with script | ||
""" | ||
match tx { | ||
case t: TransferTransaction => false | ||
case mt: MassTransferTransaction => false | ||
case ss: SetScriptTransaction => false | ||
case _ => sigVerify(tx.bodyBytes, tx.proofs[0], tx.senderPublicKey) | ||
} | ||
""" | ||
When Alice tries to transfer 10 LTO to Bob | ||
Then the transaction fails | ||
When Alice tries to remove the account script | ||
Then the transaction fails | ||
When Alice tries to anchor | ||
Then the transaction is successful |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,3 @@ | ||
lto~=1.1.2 | ||
lto~=1.2.1 | ||
behave~=1.2.6 | ||
polling~=0.3.2 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
from behave import * | ||
from e2e.common.tools import NODE, funds_for_transaction, broadcast | ||
from lto.transactions import SetScript | ||
|
||
|
||
def set_script(context, user, script): | ||
transaction = NODE.compile(script) | ||
transaction.sign_with(context.users[user]) | ||
broadcast(context, transaction) | ||
|
||
def clear_script(context, user): | ||
transaction = SetScript() | ||
transaction.sign_with(context.users[user]) | ||
broadcast(context, transaction) | ||
|
||
def has_script(context, user): | ||
response = NODE.wrapper('/addresses/scriptInfo/{}'.format(context.users[user].address)) | ||
return 'script' in response | ||
|
||
@given("{user} has a smart account with script") | ||
def step_impl(context, user): | ||
funds_for_transaction(context, user, SetScript.DEFAULT_FEE) | ||
set_script(context, user, context.text) | ||
assert has_script(context, user), "No script set for account {}".format(context.users[user].address) | ||
|
||
@when("{user} creates a smart account with script") | ||
def step_impl(context, user): | ||
set_script(context, user, context.text) | ||
|
||
@when("{user} removes the account script") | ||
def step_impl(context, user): | ||
clear_script(context, user) | ||
|
||
@when("{user} tries to remove the account script") | ||
def step_impl(context, user): | ||
try: | ||
clear_script(context, user) | ||
except: | ||
pass | ||
|
||
@then("{user} has a smart account") | ||
def step_impl(context, user): | ||
assert has_script(context, user), "No script set for account {}".format(context.users[user].address) | ||
|
||
@then("{user} doesn't have a smart account") | ||
def step_impl(context, user): | ||
assert not has_script(context, user), "Account {} has a script".format(context.users[user].address) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.