Skip to content

Commit

Permalink
Wip-fix e2e test build
Browse files Browse the repository at this point in the history
  • Loading branch information
hrajchert committed Aug 8, 2023
1 parent c7a243e commit 63c09a4
Show file tree
Hide file tree
Showing 28 changed files with 216 additions and 215 deletions.
28 changes: 19 additions & 9 deletions Readme.md
Original file line number Diff line number Diff line change
@@ -1,17 +1,26 @@
# WIP WARNING
> The TypeScript SDK is a work in progress, it's API might change so use with caution.
# Marlowe TS-SDK
TODO
The Marlowe TypeScript SDK is a set of libraries and utilities to work with Marlowe contracts. The project uses [npm workspaces](https://docs.npmjs.com/cli/v7/using-npm/workspaces) to divide itself in the following packages:

* `language/core/v1`: The `@marlowe/language-core-v1` library that contains the core Marlowe language definitions and utilities.
* `legacy-adapter`: The `@marlowe/legacy-adapter` library that contains common utilities.
* `legacy-runtime`: The `@marlowe/legacy-runtime` library that contains the initial abstraction over the Marlowe runtime

## Developer notes

### Build

To build all packages
In order to start develop the SDK you need to install the dependencies and build the packages.

```
$ npm i
$ npm run build
```

To build a single package
If you want to build a single package you can use the `-w` flag or execute the build command from the package folder.

```
# From the root folder
$ npm run build -w @marlowe/language-core-v1
Expand All @@ -20,20 +29,21 @@ $ cd packages/language/core/v1
$ npm run build
```

To clean all packages
In order to clean the build artifacts you can use the `clean` command.

```
$ npm run clean
```

To run the unit test you can execute the `test` command.

TODO migrage
"test": "yarn node --experimental-vm-modules $(yarn bin jest -c ./jest.config.js)"


### Run tests
```
$ npm run test
```

### E2E tests

TODO: Fix the E2E tests
In order to run the E2E tests you need to create a `env/.env.test` file that points to a working version of the marlowe runtime and a working Blockfrost instance and a faucet PK

TODO: explain how to get the Faucet PK
Expand Down
49 changes: 0 additions & 49 deletions jest.config-deprecated.js

This file was deleted.

1 change: 0 additions & 1 deletion jest.config.console-deprecated.js

This file was deleted.

1 change: 1 addition & 0 deletions packages/language/core/v1/src/examples/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
export * as SwapADAToken from './swaps/swap-token-token.js';
export {oneNotifyTrue} from './contract-one-notify.js';



Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ export const Token = t.type({currency_symbol:PolicyId,token_name:TokenName})
export const token = (currency_symbol :PolicyId,token_name: TokenName) => ({ currency_symbol: currency_symbol, token_name: token_name })


export const toString : (token : Token) => string = (token) => `${token.currency_symbol}|${token.token_name}`
export const tokenToString : (token : Token) => string = (token) => `${token.currency_symbol}|${token.token_name}`

export const lovelaceToken : Token = token('','')
export const adaToken: Token = lovelaceToken
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,7 @@
import * as t from "io-ts"
import { PolicyId } from "./policyId.js";
import * as T from "./token.js";



export const toString : (token : TokenValue) => string = (tokenValue) => `${tokenValue.amount} - ${T.toString(tokenValue.token)}`
export const toString : (token : TokenValue) => string = (tokenValue) => `${tokenValue.amount} - ${T.tokenToString(tokenValue.token)}`


export type TokenValue = t.TypeOf<typeof TokenValue>
Expand Down
9 changes: 7 additions & 2 deletions packages/language/core/v1/src/semantics/contract/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,19 @@ import { Let } from "./let.js";
import { Pay } from "./pay.js";
import { When } from "./when/index.js";
export { Assert } from "./assert.js";
export { Close } from "./close.js";
export { Close, close } from "./close.js";
export { If } from "./if.js";
export { Let } from "./let.js";
export { Pay } from "./pay.js";
export { When } from "./when/index.js";
export { When, datetoTimeout } from "./when/index.js";
export { Action } from "./when/action/index.js";
export { inputNotify } from "./when/input/notify.js";
export { Input, BuiltinByteString } from "./when/input/index.js";
export { Value } from "./common/value.js";
export { Accounts } from "./common/payee/account.js";
export { Token, TokenName, tokenToString, token } from './common/token.js';
export { TokenValue, tokenValue, adaValue } from './common/tokenValue.js';
export { PolicyId } from './common/policyId.js';

export type Contract =
| Close
Expand Down
1 change: 1 addition & 0 deletions packages/language/core/v1/src/semantics/next/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import * as t from "io-ts";
import { ApplicableInputs } from "./applicables/index.js";
export { toInput } from "./applicables/canDeposit.js";

export type Next = t.TypeOf<typeof Next>
export const Next
Expand Down
8 changes: 6 additions & 2 deletions packages/legacy-runtime/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,18 @@
"scripts": {
"build": "tsc --build src",
"clean": "tsc --build --clean src",
"test": "echo 'runtime test'"
"test": "echo 'The legact runtime doesnt have unit tests'",
"test:e2e": "NODE_OPTIONS='--experimental-vm-modules --no-warnings' jest --config test/jest.e2e.config.mjs",
"build:e2e": "tsc --build test"
},
"type": "module",
"exports": {
".": "./dist/index.js",
"./restAPI": "./dist/restAPI.js",
"./runtimeCIP30": "./dist/runtimeCIP30.js",
"./runtimeSingleAddress": "./dist/runtimeSingleAddress.js"
"./runtimeSingleAddress": "./dist/runtimeSingleAddress.js",
"./transaction": "./dist/contract/transaction/index.js",
"./write/command": "./dist/write/command.js"
},
"dependencies": {
"@blockfrost/blockfrost-js": "5.2.0",
Expand Down
9 changes: 4 additions & 5 deletions packages/legacy-runtime/src/contract/details.ts
Original file line number Diff line number Diff line change
@@ -1,16 +1,15 @@

import { ContractId } from "./id.js";
import { TextEnvelope } from "../common/textEnvelope.js";
import { optionFromNullable } from "io-ts-types";
import * as t from "io-ts";
import { Contract } from "@marlowe/language-core-v1";
import { MarloweState } from "@marlowe/language-core-v1/state";
import { ContractId } from "./id.js";
import { TextEnvelope } from "../common/textEnvelope.js";
import { BlockHeader } from "../common/block.js";
import { MarloweVersion } from "../common/version.js";
import { PolicyId } from "../common/policyId.js";
import { Metadata } from "../common/metadata/index.js";
import { TxStatus } from "./transaction/status.js";
import { TxOutRef } from "../common/tx/outRef.js";
import { Contract } from "@marlowe/language-core-v1/semantics/contract/index.js";
import { MarloweState } from "@marlowe/language-core-v1/semantics/state.js";
import { RoleName } from "./role.js";


Expand Down
23 changes: 10 additions & 13 deletions packages/legacy-runtime/src/contract/endpoints/collection.ts
Original file line number Diff line number Diff line change
@@ -1,34 +1,31 @@

import { AxiosInstance, ParamEncoder, ParamsSerializerOptions } from 'axios';

import * as t from "io-ts";
import * as TE from 'fp-ts/lib/TaskEither.js'
import { pipe } from 'fp-ts/lib/function.js';
import * as E from 'fp-ts/lib/Either.js'
import * as A from 'fp-ts/lib/Array.js'
import * as O from 'fp-ts/lib/Option.js';
import { Newtype, iso } from 'newtype-ts'
import { formatValidationErrors } from 'jsonbigint-io-ts-reporters'
import { fromNewtype, optionFromNullable } from 'io-ts-types';
import { stringify } from 'qs';

import { Contract } from '@marlowe/language-core-v1';

import * as HTTP from '../../common/http.js';
import { Header } from '../header.js';

import { RolesConfig } from '../role.js';

import { Metadata, Tag, Tags } from '../../common/metadata/index.js';

import { TextEnvelope } from '../../common/textEnvelope.js';
import { ContractId } from '../id.js';
import * as t from "io-ts";
import { formatValidationErrors } from 'jsonbigint-io-ts-reporters'
import { DecodingError } from '../../common/codec.js';
import * as E from 'fp-ts/lib/Either.js'
import * as A from 'fp-ts/lib/Array.js'
import { MarloweVersion } from '../../common/version.js';
import { unAddressBech32 } from '../../common/address.js';

import { fromNewtype, optionFromNullable } from 'io-ts-types';
import * as O from 'fp-ts/lib/Option.js';
import { Contract } from '@marlowe/language-core-v1/semantics/contract/index.js';
import { AddressesAndCollaterals } from '../../wallet/api.js';
import { stringify } from 'qs';
import { unTxOutRef } from '../../common/tx/outRef.js';


export interface ContractsRange extends Newtype<{ readonly ContractsRange: unique symbol }, string> {}
export const ContractsRange = fromNewtype<ContractsRange>(t.string)
export const unContractsRange = iso<ContractsRange>().unwrap
Expand Down
4 changes: 2 additions & 2 deletions packages/legacy-runtime/src/contract/role.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { AddressBech32 } from "../common/address.js";
import * as t from "io-ts"
import { PolicyId } from "@marlowe/language-core-v1/semantics/contract/common/policyId.js";
import { optionFromNullable } from "io-ts-types";
import { PolicyId } from "@marlowe/language-core-v1";
import { AddressBech32 } from "../common/address.js";

export type RoleName = string
export const RoleName = t.string
Expand Down
12 changes: 7 additions & 5 deletions packages/legacy-runtime/src/contract/transaction/details.ts
Original file line number Diff line number Diff line change
@@ -1,17 +1,19 @@
import { optionFromNullable } from "io-ts-types";
import * as t from "io-ts";

import { ISO8601 } from "@marlowe/legacy-adapter/time";
import { BuiltinByteString, Input } from "@marlowe/language-core-v1";
import { MarloweState } from "@marlowe/language-core-v1/state";
import { Contract } from "@marlowe/language-core-v1";

import { BlockHeader } from "../../common/block.js";
import { Metadata } from "../../common/metadata/index.js";
import { ContractId } from "../id.js";
import { TransactionId } from "./id.js";
import { TxOutRef } from "../../common/tx/outRef.js";
import { TxStatus } from "./status.js";
import * as t from "io-ts";
import { BuiltinByteString, Input } from "@marlowe/language-core-v1/semantics/contract/when/input/index.js";
import { Tags } from "../../common/metadata/tag.js";
import { Contract } from "@marlowe/language-core-v1/semantics/contract/index.js";
import { MarloweState } from "@marlowe/language-core-v1/semantics/state.js";
import { TxId } from "../../common/tx/id.js";
import { ISO8601 } from "@marlowe/legacy-adapter/time";
import { TextEnvelope } from "../../common/textEnvelope.js";

export type Details = t.TypeOf<typeof Details>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,22 +4,22 @@ import * as E from 'fp-ts/lib/Either.js'
import * as A from 'fp-ts/lib/Array.js'
import * as O from 'fp-ts/lib/Option.js';
import * as TE from 'fp-ts/lib/TaskEither.js'
import { pipe } from 'fp-ts/lib/function.js';
import { formatValidationErrors } from "jsonbigint-io-ts-reporters";
import { fromNewtype, optionFromNullable } from 'io-ts-types';
import { pipe } from 'fp-ts/lib/function.js';

import { AxiosInstance } from "axios";

import { ISO8601 } from "@marlowe/legacy-adapter/time";
import { Input } from "@marlowe/language-core-v1";

import * as HTTP from '../../../common/http.js';
import { unAddressBech32 } from "../../../common/address.js";
import { Metadata } from "../../../common/metadata/index.js";
import { AddressesAndCollaterals } from "../../../wallet/api.js";
import { DecodingError } from "../../../common/codec.js";
import { TextEnvelope } from "../../../common/textEnvelope.js";
import { MarloweVersion } from "../../../common/version.js";
import { ISO8601 } from "@marlowe/legacy-adapter/time";
import { Tags } from "../../../common/metadata/tag.js";
import { Input } from "@marlowe/language-core-v1/semantics/contract/when/input/index.js";
import { Header } from "../header.js";
import { TransactionId } from ".././id.js";
import { ContractId, unContractId } from "../../id.js";
Expand Down
5 changes: 3 additions & 2 deletions packages/legacy-runtime/src/contract/transaction/header.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
import * as t from "io-ts";
import { optionFromNullable } from "io-ts-types";
import { BuiltinByteString } from "@marlowe/language-core-v1";

import { BlockHeader } from "../../common/block.js";
import { Metadata } from "../../common/metadata/index.js";
import { ContractId } from "../id.js";
import { TransactionId } from "./id.js";
import { TxOutRef } from "../../common/tx/outRef.js";
import { TxStatus } from "./status.js";
import * as t from "io-ts";
import { BuiltinByteString } from "@marlowe/language-core-v1/semantics/contract/when/input/index.js";
import { Tags } from "../../common/metadata/tag.js";

export type Header = t.TypeOf<typeof Header>
Expand Down
1 change: 1 addition & 0 deletions packages/legacy-runtime/src/contract/transaction/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export * from "./id.js"
2 changes: 1 addition & 1 deletion packages/legacy-runtime/src/runtimeSingleAddress.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { pipe } from 'fp-ts/lib/function.js';

import * as S from './wallet/singleAddress/index.js';
import { mkRuntime, Runtime } from './index.js';

export {Context, SingleAddressWallet, PrivateKeysAsHex, getPrivateKeyFromHexString} from './wallet/singleAddress/index.js';


export const mkRuntimeSingleAddress
Expand Down
12 changes: 7 additions & 5 deletions packages/legacy-runtime/src/wallet/singleAddress/index.ts
Original file line number Diff line number Diff line change
@@ -1,17 +1,19 @@
import { pipe } from 'fp-ts/lib/function.js';
import * as A from 'fp-ts/lib/Array.js';
import * as API from '@blockfrost/blockfrost-js'
import { Blockfrost, Lucid, C, Network, PrivateKey, PolicyId, getAddressDetails, toUnit, fromText, NativeScript, Tx , TxSigned, TxComplete, Script, fromHex, toHex, Core, fromUnit, Unit } from 'lucid-cardano';
import * as A from 'fp-ts/lib/Array.js';
import { pipe } from 'fp-ts/lib/function.js';
import * as O from 'fp-ts/lib/Option.js'
import { log } from '@marlowe/legacy-adapter/logging'
import * as TE from 'fp-ts/lib/TaskEither.js'
import * as T from 'fp-ts/lib/Task.js'

import { Token, token, TokenValue, adaValue, tokenValue } from '@marlowe/language-core-v1';
import { log } from '@marlowe/legacy-adapter/logging'

import { WalletAPI } from '../api.js';
import { addressBech32, AddressBech32, unAddressBech32 } from '../../common/address.js';
import { HexTransactionWitnessSet , MarloweTxCBORHex} from '../../common/textEnvelope.js';
import { TxOutRef } from '../../common/tx/outRef.js';
import { Token, token } from '@marlowe/language-core-v1/semantics/contract/common/token.js';
import { TokenValue, adaValue, tokenValue } from '@marlowe/language-core-v1/semantics/contract/common/tokenValue.js';
export { PrivateKeysAsHex } from "./privateKeys.js";


export type Address = string;
Expand Down
9 changes: 4 additions & 5 deletions packages/legacy-runtime/test/context.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Network } from "lucid-cardano";
import { Context, getPrivateKeyFromHexString } from "../../src/wallet/singleAddress";
import { Context, getPrivateKeyFromHexString } from '@marlowe/legacy-runtime/runtimeSingleAddress';


export function getBlockfrostContext () : Context {
Expand All @@ -8,15 +8,14 @@ export function getBlockfrostContext () : Context {
, BLOCKFROST_URL as string
, NETWORK_ID as Network);
};

export function getBankPrivateKey () : string {
const { BANK_PK_HEX } = process.env;
return getPrivateKeyFromHexString(BANK_PK_HEX as string)
}

export function getMarloweRuntimeUrl () : string {
const { MARLOWE_WEB_SERVER_URL} = process.env;
return MARLOWE_WEB_SERVER_URL as string
};



Loading

0 comments on commit 63c09a4

Please sign in to comment.