Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adjust the parameter sequence of the tokenization API #23

Merged
merged 2 commits into from
Sep 24, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
423 changes: 227 additions & 196 deletions src/masternodes/mn_rpc.cpp

Large diffs are not rendered by default.

25 changes: 12 additions & 13 deletions src/rpc/client.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -177,25 +177,24 @@ static const CRPCConvertParam vRPCConvertParams[] =
{ "resignmasternode", 1, "inputs" },
{ "listmasternodes", 0, "pagination" },
{ "listmasternodes", 1, "verbose" },
{ "createtoken", 0, "inputs" },
{ "createtoken", 1, "metadata" },
{ "updatetoken", 0, "inputs" },
{ "updatetoken", 1, "metadata" },
{ "destroytoken", 0, "inputs" },
{ "createtoken", 0, "metadata" },
{ "createtoken", 1, "inputs"},
{ "updatetoken", 0, "metadata"},
{ "updatetoken", 1, "inputs"},
{ "destroytoken", 1, "inputs" },
{ "listtokens", 0, "pagination" },
{ "listtokens", 1, "verbose" },
{ "gettoken", 0, "key" },
{ "minttokens", 0, "inputs" },
{ "minttokens", 1, "amounts" },
{ "utxostoaccount", 0, "inputs" },
{ "utxostoaccount", 1, "amounts" },
{ "minttokens", 1, "inputs"},
{ "utxostoaccount", 0, "amounts" },
{ "utxostoaccount", 1, "inputs" },
{ "listaccounts", 0, "pagination" },
{ "listaccounts", 1, "verbose" },
{ "getaccount", 1, "pagination" },
{ "accounttoaccount", 0, "inputs" },
{ "accounttoaccount", 2, "to" },
{ "accounttoutxos", 0, "inputs" },
{ "accounttoutxos", 2, "to" },
{ "accounttoaccount", 1, "to" },
{ "accounttoaccount", 2, "inputs" },
{ "accounttoutxos", 1, "to" },
{ "accounttoutxos", 2, "inputs" },

{ "spv_sendrawtx", 0, "rawtx" },
{ "spv_createanchor", 0, "inputs" },
Expand Down
36 changes: 18 additions & 18 deletions test/functional/feature_accounts_n_utxos.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,41 +48,41 @@ def run_test(self):
#========================
# missing from (account)
try:
self.nodes[0].accounttoaccount([], self.nodes[0].getnewaddress("", "legacy"), {toGold: "100@GOLD"})
self.nodes[0].accounttoaccount(self.nodes[0].getnewaddress("", "legacy"), {toGold: "100@GOLD"}, [])
except JSONRPCException as e:
errorString = e.error['message']
assert("Can't find any UTXO" in errorString)

# missing from (account exist, but no tokens)
try:
self.nodes[0].accounttoaccount([], accountGold, {toGold: "100@SILVER"})
self.nodes[0].accounttoaccount(accountGold, {toGold: "100@SILVER"}, [])
except JSONRPCException as e:
errorString = e.error['message']
assert("not enough balance" in errorString)

# missing amount
try:
self.nodes[0].accounttoaccount([], accountGold, {toGold: ""})
self.nodes[0].accounttoaccount(accountGold, {toGold: ""}, [])
except JSONRPCException as e:
errorString = e.error['message']
assert("Invalid amount" in errorString)

#invalid UTXOs
try:
self.nodes[0].accounttoaccount([{"": 0}], accountGold, {toGold: "100@GOLD"})
self.nodes[0].accounttoaccount(accountGold, {toGold: "100@GOLD"}, [{"": 0}])
except JSONRPCException as e:
errorString = e.error['message']
assert("JSON value is not a string as expected" in errorString)

# missing (account exists, but does not belong)
try:
self.nodes[0].accounttoaccount([], accountSilver, {accountGold: "100@SILVER"})
self.nodes[0].accounttoaccount(accountSilver, {accountGold: "100@SILVER"}, [])
except JSONRPCException as e:
errorString = e.error['message']
assert("Can't find any UTXO" in errorString)

# transfer
self.nodes[0].accounttoaccount([], accountGold, {toGold: "100@GOLD"})
self.nodes[0].accounttoaccount(accountGold, {toGold: "100@GOLD"}, [])
self.nodes[0].generate(1)

assert_equal(self.nodes[0].getaccount(accountGold, {}, True)[idGold], initialGold - 100)
Expand All @@ -92,7 +92,7 @@ def run_test(self):
assert_equal(self.nodes[0].getaccount(toGold, {}, True)[idGold], self.nodes[1].getaccount(toGold, {}, True)[idGold])

# transfer between nodes
self.nodes[1].accounttoaccount([], accountSilver, {toSilver: "100@SILVER"})
self.nodes[1].accounttoaccount(accountSilver, {toSilver: "100@SILVER"}, [])
self.nodes[1].generate(1)

assert_equal(self.nodes[1].getaccount(accountSilver, {}, True)[idSilver], initialSilver - 100)
Expand All @@ -103,78 +103,78 @@ def run_test(self):

# missing (account exists, there are tokens, but not token 0)
try:
self.nodes[0].accounttoaccount([], toSilver, {accountGold: "100@SILVER"})
self.nodes[0].accounttoaccount(toSilver, {accountGold: "100@SILVER"}, [])
except JSONRPCException as e:
errorString = e.error['message']
assert("Can't find any UTXO" in errorString)

# utxostoaccount
#========================
try:
self.nodes[0].utxostoaccount([], {toGold: "100@GOLD"})
self.nodes[0].utxostoaccount({toGold: "100@GOLD"}, [])
except JSONRPCException as e:
errorString = e.error['message']
assert("Insufficient funds" in errorString)

# missing amount
try:
self.nodes[0].utxostoaccount([], {toGold: ""})
self.nodes[0].utxostoaccount({toGold: ""}, [])
except JSONRPCException as e:
errorString = e.error['message']
assert("Invalid amount" in errorString)

#invalid UTXOs
try:
self.nodes[0].utxostoaccount([{"": 0}], {accountGold: "100@DFI"})
self.nodes[0].utxostoaccount({accountGold: "100@DFI"}, [{"": 0}])
except JSONRPCException as e:
errorString = e.error['message']
assert("Invalid amount" in errorString)

# transfer
initialBalance = self.nodes[0].getbalances()['mine']['trusted']
self.nodes[0].utxostoaccount([], {accountGold: "100@DFI"})
self.nodes[0].utxostoaccount({accountGold: "100@DFI"}, [])
self.nodes[0].generate(1)
assert(initialBalance != self.nodes[0].getbalances()['mine']['trusted'])

# accounttoutxos
#========================
# missing from (account)
try:
self.nodes[0].accounttoutxos([], self.nodes[0].getnewaddress("", "legacy"), {toGold: "100@GOLD"})
self.nodes[0].accounttoutxos(self.nodes[0].getnewaddress("", "legacy"), {toGold: "100@GOLD"}, [])
except JSONRPCException as e:
errorString = e.error['message']
assert("Can't find any UTXO" in errorString)

# missing amount
try:
self.nodes[0].accounttoutxos([], accountGold, {accountGold: ""})
self.nodes[0].accounttoutxos(accountGold, {accountGold: ""}, [])
except JSONRPCException as e:
errorString = e.error['message']
assert("Invalid amount" in errorString)

#invalid UTXOs
try:
self.nodes[0].accounttoutxos([{"": 0}], accountGold, {accountGold: "100@GOLD"})
self.nodes[0].accounttoutxos(accountGold, {accountGold: "100@GOLD"}, [{"": 0}])
except JSONRPCException as e:
errorString = e.error['message']
assert("JSON value is not a string as expected" in errorString)

# missing (account exists, but does not belong)
try:
self.nodes[0].accounttoutxos([], accountSilver, {accountGold: "100@SILVER"})
self.nodes[0].accounttoutxos(accountSilver, {accountGold: "100@SILVER"}, [])
except JSONRPCException as e:
errorString = e.error['message']
assert("Can't find any UTXO" in errorString)

# missing (account exists, there are tokens, but not token 0)
try:
self.nodes[0].accounttoutxos([], toSilver, {accountGold: "100@SILVER"})
self.nodes[0].accounttoutxos(toSilver, {accountGold: "100@SILVER"}, [])
except JSONRPCException as e:
errorString = e.error['message']
assert("Can't find any UTXO" in errorString)

# transfer
self.nodes[0].accounttoutxos([], accountGold, {accountGold: "100@GOLD"})
self.nodes[0].accounttoutxos(accountGold, {accountGold: "100@GOLD"}, [])
self.nodes[0].generate(1)

assert_equal(self.nodes[0].getaccount(accountGold, {}, True)[idGold], initialGold - 200)
Expand Down
14 changes: 7 additions & 7 deletions test/functional/feature_tokens_basic.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,22 +39,22 @@ def run_test(self):

# Fail to create: Insufficient funds (not matured coins)
try:
createTokenTx = self.nodes[0].createtoken([], {
createTokenTx = self.nodes[0].createtoken({
"symbol": "GOLD",
"name": "shiny gold",
"collateralAddress": collateral0
})
}, [])
except JSONRPCException as e:
errorString = e.error['message']
assert("Insufficient funds" in errorString)

print ("Create token 'GOLD' (128)...")
self.nodes[0].generate(1)
createTokenTx = self.nodes[0].createtoken([], {
createTokenTx = self.nodes[0].createtoken({
"symbol": "GOLD",
"name": "shiny gold",
"collateralAddress": collateral0
})
}, [])

# Create and sign (only) collateral spending tx
spendTx = self.nodes[0].createrawtransaction([{'txid':createTokenTx, 'vout':1}],[{collateral0:9.999}])
Expand Down Expand Up @@ -107,7 +107,7 @@ def run_test(self):
#========================
# Try to resign w/o auth (no money on auth/collateral address)
try:
self.nodes[0].destroytoken([], "GOLD")
self.nodes[0].destroytoken("GOLD", [])
except JSONRPCException as e:
errorString = e.error['message']
assert("Can't find any UTXO's" in errorString)
Expand All @@ -117,13 +117,13 @@ def run_test(self):
self.nodes[0].generate(1)

print ("Destroy token...")
destroyTx = self.nodes[0].destroytoken([], "GOLD")
destroyTx = self.nodes[0].destroytoken("GOLD", [])
self.nodes[0].generate(1)
assert_equal(self.nodes[0].listtokens()['128']['destructionTx'], destroyTx)

# Try to mint destroyed token ('minting' is not the task of current test, but let's check it here)
try:
self.nodes[0].minttokens([], "100@GOLD")
self.nodes[0].minttokens("100@GOLD", [])
except JSONRPCException as e:
errorString = e.error['message']
assert("already destroyed" in errorString)
Expand Down
20 changes: 10 additions & 10 deletions test/functional/feature_tokens_dat.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,12 +40,12 @@ def run_test(self):
self.nodes[0].generate(1)

# 1 Creating DAT token
self.nodes[0].createtoken([], {
self.nodes[0].createtoken({
"symbol": "PT",
"name": "Platinum",
"isDAT": True,
"collateralAddress": collateral0
})
}, [])

self.nodes[0].generate(1)
self.sync_blocks([self.nodes[0], self.nodes[2]])
Expand All @@ -62,7 +62,7 @@ def run_test(self):

# 2 Trying to make it regular
try:
self.nodes[0].updatetoken([], {"token": "PT", "isDAT": False})
self.nodes[0].updatetoken({"token": "PT", "isDAT": False}, [])
except JSONRPCException as e:
errorString = e.error['message']
assert("Token PT is a 'stable coin'" in errorString)
Expand All @@ -77,12 +77,12 @@ def run_test(self):

# 3 Trying to make regular token
self.nodes[0].generate(1)
createTokenTx = self.nodes[0].createtoken([], {
createTokenTx = self.nodes[0].createtoken({
"symbol": "GOLD",
"name": "shiny gold",
"isDAT": False,
"collateralAddress": collateral0
})
}, [])
self.nodes[0].generate(1)
# Checks
tokens = self.nodes[0].listtokens()
Expand All @@ -94,13 +94,13 @@ def run_test(self):

# 4 Trying to make it DAT not from Foundation
try:
self.nodes[2].updatetoken([], {"token": "GOLD", "isDAT": True})
self.nodes[2].updatetoken({"token": "GOLD", "isDAT": True}, [])
except JSONRPCException as e:
errorString = e.error['message']
assert("Incorrect Authorization" in errorString)

# 5 Making token isDAT from Foundation
self.nodes[0].updatetoken([], {"token": "GOLD", "isDAT": True})
self.nodes[0].updatetoken({"token": "GOLD", "isDAT": True}, [])

self.nodes[0].generate(1)
# Checks
Expand All @@ -116,7 +116,7 @@ def run_test(self):
assert_equal(tokens['128']["isDAT"], True)

# 7 Removing DAT
self.nodes[0].updatetoken([], {"token": "GOLD", "isDAT": False})
self.nodes[0].updatetoken({"token": "GOLD", "isDAT": False}, [])

self.nodes[0].generate(1)

Expand All @@ -127,12 +127,12 @@ def run_test(self):
self.nodes[0].generate(1)

# 8 Creating DAT token
self.nodes[0].createtoken([], {
self.nodes[0].createtoken({
"symbol": "TEST",
"name": "TEST token",
"isDAT": True,
"collateralAddress": collateral0
})
}, [])

self.nodes[0].generate(1)

Expand Down
16 changes: 8 additions & 8 deletions test/functional/feature_tokens_minting.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,16 +30,16 @@ def run_test(self):
#========================
collateralGold = self.nodes[0].getnewaddress("", "legacy")
collateralSilver = self.nodes[0].getnewaddress("", "legacy")
self.nodes[0].createtoken([], {
self.nodes[0].createtoken({
"symbol": "GOLD",
"name": "shiny gold",
"collateralAddress": collateralGold
})
self.nodes[0].createtoken([], {
}, [])
self.nodes[0].createtoken({
"symbol": "SILVER",
"name": "just silver",
"collateralAddress": collateralSilver
})
}, [])

self.nodes[0].generate(1)
# At this point, tokens was created
Expand All @@ -63,13 +63,13 @@ def run_test(self):
# print(self.nodes[0].listunspent())

alienMintAddr = self.nodes[1].getnewaddress("", "legacy")
self.nodes[0].minttokens([], "300@GOLD")
self.nodes[0].minttokens([], "3000@SILVER")
self.nodes[0].minttokens("300@GOLD", [])
self.nodes[0].minttokens("3000@SILVER", [])
self.nodes[0].generate(1)
self.sync_blocks()

self.nodes[0].accounttoutxos([], collateralGold, { self.nodes[0].getnewaddress("", "legacy"): "100@GOLD", alienMintAddr: "200@GOLD"})
self.nodes[0].accounttoutxos([], collateralSilver, { self.nodes[0].getnewaddress("", "legacy"): "1000@SILVER", alienMintAddr: "2000@SILVER"})
self.nodes[0].accounttoutxos(collateralGold, { self.nodes[0].getnewaddress("", "legacy"): "100@GOLD", alienMintAddr: "200@GOLD"}, [])
self.nodes[0].accounttoutxos(collateralSilver, { self.nodes[0].getnewaddress("", "legacy"): "1000@SILVER", alienMintAddr: "2000@SILVER"}, [])
self.nodes[0].generate(1)
self.sync_blocks()

Expand Down
12 changes: 6 additions & 6 deletions test/functional/test_framework/test_framework.py
Original file line number Diff line number Diff line change
Expand Up @@ -325,24 +325,24 @@ def setup_tokens(self):
self.nodes[0].generate(100)
self.sync_all()

self.nodes[0].createtoken([], {
self.nodes[0].createtoken({
"symbol": "GOLD",
"name": "shiny gold",
"collateralAddress": self.nodes[0].get_genesis_keys().ownerAuthAddress # collateralGold
})
self.nodes[1].createtoken([], {
}, [])
self.nodes[1].createtoken({
"symbol": "SILVER",
"name": "just silver",
"collateralAddress": self.nodes[1].get_genesis_keys().ownerAuthAddress # collateralSilver
})
}, [])
self.sync_mempools()
self.nodes[0].generate(1)
# At this point, tokens was created
tokens = self.nodes[0].listtokens()
assert_equal(len(tokens), 3)

self.nodes[0].minttokens([], "1000@GOLD")
self.nodes[1].minttokens([], "2000@SILVER")
self.nodes[0].minttokens("1000@GOLD", [])
self.nodes[1].minttokens("2000@SILVER", [])
self.sync_mempools()
self.nodes[0].generate(1)

Expand Down