From efcc69bf75c5cefb75a8ef05d4a84933ba163579 Mon Sep 17 00:00:00 2001 From: Vladislav Prekel Date: Wed, 6 Jul 2022 09:15:56 +0700 Subject: [PATCH] tests: add sample for #851 --- tests/OptionalDateTime/README.md | 7 + tests/OptionalDateTime/data.json | 6 + tests/OptionalDateTime/logic/logic.ergo | 23 ++ ...cordproject.org.accordproject.contract.cto | 32 +++ ...dproject.org.accordproject.money@0.2.0.cto | 244 ++++++++++++++++++ ...ccordproject.org.accordproject.runtime.cto | 51 ++++ .../@models.accordproject.org.time@0.2.0.cto | 84 ++++++ .../model/@org.accordproject.ergo.options.cto | 20 ++ tests/OptionalDateTime/model/model.cto | 18 ++ tests/OptionalDateTime/package.json | 26 ++ tests/OptionalDateTime/request.json | 1 + tests/OptionalDateTime/text/grammar.tem.md | 45 ++++ 12 files changed, 557 insertions(+) create mode 100644 tests/OptionalDateTime/README.md create mode 100644 tests/OptionalDateTime/data.json create mode 100644 tests/OptionalDateTime/logic/logic.ergo create mode 100644 tests/OptionalDateTime/model/@models.accordproject.org.accordproject.contract.cto create mode 100644 tests/OptionalDateTime/model/@models.accordproject.org.accordproject.money@0.2.0.cto create mode 100644 tests/OptionalDateTime/model/@models.accordproject.org.accordproject.runtime.cto create mode 100644 tests/OptionalDateTime/model/@models.accordproject.org.time@0.2.0.cto create mode 100644 tests/OptionalDateTime/model/@org.accordproject.ergo.options.cto create mode 100644 tests/OptionalDateTime/model/model.cto create mode 100644 tests/OptionalDateTime/package.json create mode 100644 tests/OptionalDateTime/request.json create mode 100644 tests/OptionalDateTime/text/grammar.tem.md diff --git a/tests/OptionalDateTime/README.md b/tests/OptionalDateTime/README.md new file mode 100644 index 000000000..f697aeed7 --- /dev/null +++ b/tests/OptionalDateTime/README.md @@ -0,0 +1,7 @@ +# Issue 851 sample + +https://github.com/accordproject/ergo/issues/851 + +``` +cicero draft --template . --data ./data.json --unquoteVariables +``` \ No newline at end of file diff --git a/tests/OptionalDateTime/data.json b/tests/OptionalDateTime/data.json new file mode 100644 index 000000000..3ae5b08e6 --- /dev/null +++ b/tests/OptionalDateTime/data.json @@ -0,0 +1,6 @@ +{ + "$class": "org.accordproject.empty.EmptyContract", + "contractId": "573de9a8-d011-45f0-ab11-144d27941c9f", + "$identifier": "573de9a8-d011-45f0-ab11-144d27941c9f", + "myDate": "2025-01-01T00:00:00" +} \ No newline at end of file diff --git a/tests/OptionalDateTime/logic/logic.ergo b/tests/OptionalDateTime/logic/logic.ergo new file mode 100644 index 000000000..ae757976a --- /dev/null +++ b/tests/OptionalDateTime/logic/logic.ergo @@ -0,0 +1,23 @@ +/* + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +namespace org.accordproject.empty + +import org.accordproject.time.* + +contract Empty over EmptyContract { + clause donothing(request : EmptyRequest) : EmptyResponse { + return EmptyResponse{} + } +} diff --git a/tests/OptionalDateTime/model/@models.accordproject.org.accordproject.contract.cto b/tests/OptionalDateTime/model/@models.accordproject.org.accordproject.contract.cto new file mode 100644 index 000000000..13aab647f --- /dev/null +++ b/tests/OptionalDateTime/model/@models.accordproject.org.accordproject.contract.cto @@ -0,0 +1,32 @@ +/* + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +concerto version ">= 1.0.0" + +namespace org.accordproject.contract + +/** + * Contract Data + * -- Describes the structure of contracts and clauses + */ + +/* A contract is a asset -- This contains the contract data */ +abstract asset Contract identified by contractId { + o String contractId +} + +/* A clause is an asset -- This contains the clause data */ +abstract asset Clause identified by clauseId { + o String clauseId +} diff --git a/tests/OptionalDateTime/model/@models.accordproject.org.accordproject.money@0.2.0.cto b/tests/OptionalDateTime/model/@models.accordproject.org.accordproject.money@0.2.0.cto new file mode 100644 index 000000000..a5f674069 --- /dev/null +++ b/tests/OptionalDateTime/model/@models.accordproject.org.accordproject.money@0.2.0.cto @@ -0,0 +1,244 @@ +/* + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +namespace org.accordproject.money + +/** + * Represents an amount of Cryptocurrency + */ +concept DigitalMonetaryAmount { + o Double doubleValue + o DigitalCurrencyCode digitalCurrencyCode +} + +/** + * Digital Currency codes. From https://en.wikipedia.org/wiki/List_of_cryptocurrencies + */ +enum DigitalCurrencyCode { + o ADA + o BCH + o BTC + o DASH + o EOS + o ETC + o ETH + o LTC + o NEO + o XLM + o XMR + o XRP + o ZEC +} + +/** + * Represents an amount of money + */ +concept MonetaryAmount { + o Double doubleValue // convert to fixed-point? + o CurrencyCode currencyCode +} + +/** + * ISO 4217 codes. From https://en.wikipedia.org/wiki/ISO_4217 + * https://www.currency-iso.org/en/home/tables/table-a1.html + */ +enum CurrencyCode { +o AED +o AFN +o ALL +o AMD +o ANG +o AOA +o ARS +o AUD +o AWG +o AZN +o BAM +o BBD +o BDT +o BGN +o BHD +o BIF +o BMD +o BND +o BOB +o BOV +o BRL +o BSD +o BTN +o BWP +o BYN +o BZD +o CAD +o CDF +o CHE +o CHF +o CHW +o CLF +o CLP +o CNY +o COP +o COU +o CRC +o CUC +o CUP +o CVE +o CZK +o DJF +o DKK +o DOP +o DZD +o EGP +o ERN +o ETB +o EUR +o FJD +o FKP +o GBP +o GEL +o GHS +o GIP +o GMD +o GNF +o GTQ +o GYD +o HKD +o HNL +o HRK +o HTG +o HUF +o IDR +o ILS +o INR +o IQD +o IRR +o ISK +o JMD +o JOD +o JPY +o KES +o KGS +o KHR +o KMF +o KPW +o KRW +o KWD +o KYD +o KZT +o LAK +o LBP +o LKR +o LRD +o LSL +o LYD +o MAD +o MDL +o MGA +o MKD +o MMK +o MNT +o MOP +o MRU +o MUR +o MVR +o MWK +o MXN +o MXV +o MYR +o MZN +o NAD +o NGN +o NIO +o NOK +o NPR +o NZD +o OMR +o PAB +o PEN +o PGK +o PHP +o PKR +o PLN +o PYG +o QAR +o RON +o RSD +o RUB +o RWF +o SAR +o SBD +o SCR +o SDG +o SEK +o SGD +o SHP +o SLL +o SOS +o SRD +o SSP +o STN +o SVC +o SYP +o SZL +o THB +o TJS +o TMT +o TND +o TOP +o TRY +o TTD +o TWD +o TZS +o UAH +o UGX +o USD +o USN +o UYI +o UYU +o UZS +o VEF +o VND +o VUV +o WST +o XAF +o XAG +o XAU +o XBA +o XBB +o XBC +o XBD +o XCD +o XDR +o XOF +o XPD +o XPF +o XPT +o XSU +o XTS +o XUA +o XXX +o YER +o ZAR +o ZMW +o ZWL +} + +/** + * Represents a currency conversion pair and exchange rate + */ +concept CurrencyConversion { + o CurrencyCode from + o CurrencyCode to + o Double rate +} diff --git a/tests/OptionalDateTime/model/@models.accordproject.org.accordproject.runtime.cto b/tests/OptionalDateTime/model/@models.accordproject.org.accordproject.runtime.cto new file mode 100644 index 000000000..ef51edfeb --- /dev/null +++ b/tests/OptionalDateTime/model/@models.accordproject.org.accordproject.runtime.cto @@ -0,0 +1,51 @@ +/* + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +concerto version ">= 1.0.0" + +namespace org.accordproject.runtime + +import org.accordproject.contract.Contract from https://models.accordproject.org/accordproject/contract.cto + +/** + * Runtime API + * -- Describes input and output of calls to a contract's clause + */ + +/* A request is a transaction */ +transaction Request { +} + +/* A response is a transaction */ +transaction Response { +} + +/* An event that represents an obligation that needs to be fulfilled */ +abstract event Obligation identified { + /* A back reference to the governing contract that emitted this obligation */ + --> Contract contract + + /* The party that is obligated */ + --> Participant promisor optional + + /* The party that receives the performance */ + --> Participant promisee optional + + /* The time before which the obligation is fulfilled */ + o DateTime deadline optional +} + +/* A contract state is an asset -- The runtime state of the contract */ +asset State { +} diff --git a/tests/OptionalDateTime/model/@models.accordproject.org.time@0.2.0.cto b/tests/OptionalDateTime/model/@models.accordproject.org.time@0.2.0.cto new file mode 100644 index 000000000..760106e5f --- /dev/null +++ b/tests/OptionalDateTime/model/@models.accordproject.org.time@0.2.0.cto @@ -0,0 +1,84 @@ +/* + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +namespace org.accordproject.time + +/** + * Months of the year + */ +enum Month { + o January + o February + o March + o April + o May + o June + o July + o August + o September + o October + o November + o December +} + +/** + * Days of the week + */ +enum Day { + o Monday + o Tuesday + o Wednesday + o Thursday + o Friday + o Saturday + o Sunday +} + +/** + * Units for a duration. + */ +enum TemporalUnit { + o seconds + o minutes + o hours + o days + o weeks +} + +/** + * A duration. For example, 6 hours. + */ +concept Duration { + o Long amount + o TemporalUnit unit +} + +/** + * Units for a time period. + */ +enum PeriodUnit { + o days + o weeks + o months + o quarters + o years +} + +/** + * A time period. For example, 2 months. + */ +concept Period { + o Long amount + o PeriodUnit unit +} diff --git a/tests/OptionalDateTime/model/@org.accordproject.ergo.options.cto b/tests/OptionalDateTime/model/@org.accordproject.ergo.options.cto new file mode 100644 index 000000000..593185e80 --- /dev/null +++ b/tests/OptionalDateTime/model/@org.accordproject.ergo.options.cto @@ -0,0 +1,20 @@ +/* + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +namespace org.accordproject.ergo.options + +concept Options { + o Boolean wrapVariables + o Boolean template +} diff --git a/tests/OptionalDateTime/model/model.cto b/tests/OptionalDateTime/model/model.cto new file mode 100644 index 000000000..09fc3f8fe --- /dev/null +++ b/tests/OptionalDateTime/model/model.cto @@ -0,0 +1,18 @@ +namespace org.accordproject.empty + +import org.accordproject.contract.* from https://models.accordproject.org/accordproject/contract.cto +import org.accordproject.runtime.* from https://models.accordproject.org/accordproject/runtime.cto + +// Template model +asset EmptyContract extends Contract { + o DateTime myDate optional + o DateTime myDate1 optional +} + +// Request +transaction EmptyRequest extends Request { +} + +// Response +transaction EmptyResponse extends Response { +} diff --git a/tests/OptionalDateTime/package.json b/tests/OptionalDateTime/package.json new file mode 100644 index 000000000..fe55d25fc --- /dev/null +++ b/tests/OptionalDateTime/package.json @@ -0,0 +1,26 @@ +{ + "name": "empty-contract", + "displayName": "Empty Contract", + "version": "0.8.0", + "description": "This is an empty contract template to get you started.", + "author": "Accord Project", + "license": "Apache-2.0", + "accordproject": { + "template": "contract", + "cicero": "^0.23.0", + "runtime": "ergo" + }, + "devDependencies": { + "cucumber": "^5.1.0" + }, + "scripts": { + "test": "cucumber-js test -r .cucumber.js" + }, + "keywords": [ + "empty", + "contract", + "blank", + "new", + "fresh" + ] +} diff --git a/tests/OptionalDateTime/request.json b/tests/OptionalDateTime/request.json new file mode 100644 index 000000000..8838555eb --- /dev/null +++ b/tests/OptionalDateTime/request.json @@ -0,0 +1 @@ +{"$class":"org.accordproject.empty.EmptyRequest"} \ No newline at end of file diff --git a/tests/OptionalDateTime/text/grammar.tem.md b/tests/OptionalDateTime/text/grammar.tem.md new file mode 100644 index 000000000..df00b1568 --- /dev/null +++ b/tests/OptionalDateTime/text/grammar.tem.md @@ -0,0 +1,45 @@ +## MyDate Contract + +Now is: {{% now() %}} + +### myDate + +myDate is: {{myDate}} +myDate is: {{% myDate %}} + +{{% + match some(myDate) + with let? completionDate then "YES - Found myDate - " ++ toString(completionDate) + else "NO - myDate not found" +%}} + +{{% + "YES - Found myDate - " ++ toString(myDate) +%}} + +{{% + match myDate + with let? completionDate then "YES - Found myDate - " ++ toString(completionDate) + else "NO - myDate not found" +%}} + +### myDate1 + +myDate1 is: {{myDate1}} +myDate1 is: {{% myDate1 %}} + +{{% + match some(myDate1) + with let? completionDate then "YES - Found myDate1 - " ++ toString(completionDate) + else "NO - myDate1 not found" +%}} + +{{% + "YES - Found myDate1 - " ++ toString(myDate1) +%}} + +{{% + match myDate1 + with let? completionDate then "YES - Found myDate1 - " ++ toString(completionDate) + else "NO - myDate1 not found" +%}}