Created
December 15, 2022 20:56
-
-
Save smondet/284346fb772a13d1d55b7d664c45758a to your computer and use it in GitHub Desktop.
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
import smartpy as sp | |
class FA2_mini(sp.Contract): | |
def __init__(self, history, metadata): | |
self.init( | |
history = history, | |
metadata = metadata | |
) | |
@sp.entry_point | |
def transfer(self, params): | |
tx_type = sp.TRecord(to_ = sp.TAddress, | |
token_id = sp.TNat, | |
amount = sp.TNat) | |
tx_type = tx_type.layout( | |
("to_", ("token_id", "amount")) | |
) | |
transfer_type = sp.TRecord(from_ = sp.TAddress, | |
txs = sp.TList(tx_type)).layout( | |
("from_", "txs")) | |
sp.set_type(params, sp.TList(transfer_type)) | |
self.data.history.push(params) | |
@sp.entry_point | |
def default(self): | |
self.data.history = [] | |
def add_test(is_default = True): | |
@sp.add_test(name = "fa2-mini", is_default = is_default) | |
def test(): | |
scenario = sp.test_scenario() | |
scenario.h1("Fake FA2 Contract") | |
scenario.table_of_contents() | |
# sp.test_account generates ED25519 key-pairs deterministically: | |
admin = sp.test_account("Administrator") | |
alice = sp.test_account("Alice") | |
bob = sp.test_account("Robert") | |
# Let's display the accounts: | |
scenario.h2("Accounts") | |
scenario.show([admin, alice, bob]) | |
c1 = FA2_mini(history = [], metadata = sp.utils.metadata_of_url("https://example.com")) | |
scenario += c1 | |
## for the browser version. | |
if "templates" not in __name__: | |
add_test() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment