dans smartpy, paramètre de variable locale, quelle est la différence?

Sep 28 2020

dans smartpy

def aa(self) {
    value_in_func = "1234"
    msg = "abc" + value_in_func
    hex_string = msg.encode("utf-8")
    thingToSign = sp.bytes("0x" + hex_string.hex())
}

Cela fonctionne bien, mais

value = "1234"
def aa(self, value)
{
    msg = "abc" + value
    hex_string = msg.encode("utf-8")
    thingToSign = sp.bytes("0x" + hex_string.hex())
}

ne fonctionne pas. Erreur: call () manquant 1 argument positionnel: arg

Je ne connais pas la différence entre les deux.

quelle différence?

J'ai vérifié sp.verify (value_in_func == value), c'est vrai.

Réponses

1 RodrigoQuelhas Sep 28 2020 at 19:08

La raison de l'erreur est que vous ne transmettez pas de paramètre à la méthode:

Votre test doit contenir quelque chose comme ça

    c1 = YourContract(...)
    scenario += c1
    scenario += c1.aa("1234")

Et retirez le value = "1234"