【发布时间】:2022-11-19 21:49:28
【问题描述】:
Pact 语言有一个属性系统。
对于少于 3 个字符和多于 256 个字符的帐户,对 create-account 的调用应该会失败。但是,我无法让它发挥作用。
这是REPL单元测试的结果。
我原以为名称短于 3 个字符的 create-account 调用会失败。
"FAILURE: empty account names fail to create: expected failure, got result = "Write succeeded""
"FAILURE: account names not >= 3 chars fail: expected failure, got result = "Write succeeded""
"FAILURE: account names not <= 256 chars fail: expected failure, got result = "Write succeeded""
使用验证 ID 创建帐户功能
(defun create-account:string
( account:string
guard:guard )
@doc " Create a new account. "
@model [ (property (valid-account-id account)) ]
(enforce-reserved account guard)
(insert token-table account
{ "balance" : 0.0
, "guard" : guard
}
)
)
这是模型定义
(module k-token GOVERNANCE
@doc "K token smart contract"
@model
[ (defproperty conserves-mass (amount:decimal)
(= (column-delta token-table 'balance) 0.0))
(defproperty valid-account-id (accountId:string)
(and
(>= (length accountId) 3)
(<= (length accountId) 256)))
]
【问题讨论】: