-
Notifications
You must be signed in to change notification settings - Fork 76
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
5af4215
commit aa60752
Showing
60 changed files
with
1,258 additions
and
754 deletions.
There are no files selected for viewing
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
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
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
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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
export * from './mesh'; | ||
export * from './plutus'; |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
import { Data } from '@mesh/types'; | ||
|
||
export const mConStr = <T extends Data[]>( | ||
alternative: number, | ||
fields: T | ||
): Data => ({ | ||
alternative, | ||
fields, | ||
}); | ||
|
||
export const mConStr0 = <T extends Data[]>(fields: T): Data => ({ | ||
alternative: 0, | ||
fields, | ||
}); | ||
|
||
export const mConStr1 = <T extends Data[]>(fields: T): Data => ({ | ||
alternative: 1, | ||
fields, | ||
}); | ||
|
||
export const mConStr2 = <T extends Data[]>(fields: T): Data => ({ | ||
alternative: 2, | ||
fields, | ||
}); | ||
|
||
export const mMaybeStakingHash = (stakeCredential: string): Data => { | ||
if (stakeCredential === '') { | ||
return mConStr1<[]>([]); | ||
} | ||
return mConStr0([mConStr0([mConStr0([stakeCredential])])]); | ||
}; | ||
|
||
export const mPubKeyAddress = (bytes: string, stakeCredential?: string): Data => | ||
mConStr0([ | ||
{ alternative: 0, fields: [bytes] }, | ||
mMaybeStakingHash(stakeCredential || ''), | ||
]); | ||
|
||
export const mScriptAddress = (bytes: string, stakeCredential?: string): Data => | ||
mConStr0([ | ||
{ alternative: 1, fields: [bytes] }, | ||
mMaybeStakingHash(stakeCredential || ''), | ||
]); |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,121 @@ | ||
import { Asset } from '@meshsdk/core'; | ||
import { | ||
value, | ||
Value, | ||
dict, | ||
BuiltinByteString, | ||
Integer, | ||
builtinByteString, | ||
integer, | ||
Dict, | ||
parsePlutusValueToAssets, | ||
} from './'; | ||
|
||
describe('Plutus data type', () => { | ||
describe('Value', () => { | ||
test('Simple ADA Value', () => { | ||
const val: Asset[] = [{ unit: 'lovelace', quantity: '1000000' }]; | ||
const datum: Value = value(val); | ||
|
||
const nameMap = dict<BuiltinByteString, Integer>([ | ||
[builtinByteString(''), integer(1000000)], | ||
]); | ||
const valMap = dict<BuiltinByteString, Dict<BuiltinByteString, Integer>>([ | ||
[builtinByteString(''), nameMap], | ||
]); | ||
expect(JSON.stringify(datum)).toBe(JSON.stringify(valMap)); | ||
}); | ||
test('Simple token Value', () => { | ||
const val: Asset[] = [ | ||
{ | ||
unit: 'baefdc6c5b191be372a794cd8d40d839ec0dbdd3c28957267dc8170074657374696e676e657777616c2e616461', | ||
quantity: '345', | ||
}, | ||
]; | ||
const datum: Value = value(val); | ||
|
||
const nameMap = dict<BuiltinByteString, Integer>([ | ||
[builtinByteString('74657374696e676e657777616c2e616461'), integer(345)], | ||
]); | ||
const valMap = dict<BuiltinByteString, Dict<BuiltinByteString, Integer>>([ | ||
[ | ||
builtinByteString( | ||
'baefdc6c5b191be372a794cd8d40d839ec0dbdd3c28957267dc81700' | ||
), | ||
nameMap, | ||
], | ||
]); | ||
expect(JSON.stringify(datum)).toBe(JSON.stringify(valMap)); | ||
}); | ||
test('Complex Value', () => { | ||
const val: Asset[] = [ | ||
{ unit: 'lovelace', quantity: '1000000' }, | ||
{ | ||
unit: 'baefdc6c5b191be372a794cd8d40d839ec0dbdd3c28957267dc8170074657374696e676e657777616c2e616461', | ||
quantity: '345', | ||
}, | ||
{ | ||
unit: 'baefdc6c5b191be372a794cd8d40d839ec0dbdd3c28957267dc817001234', | ||
quantity: '567', | ||
}, | ||
]; | ||
const datum: Value = value(val); | ||
|
||
const nameMap = dict<BuiltinByteString, Integer>([ | ||
[builtinByteString('1234'), integer(567)], | ||
[builtinByteString('74657374696e676e657777616c2e616461'), integer(345)], | ||
]); | ||
const valMap = dict<BuiltinByteString, Dict<BuiltinByteString, Integer>>([ | ||
[ | ||
builtinByteString(''), | ||
dict([[builtinByteString(''), integer(1000000)]]), | ||
], | ||
[ | ||
builtinByteString( | ||
'baefdc6c5b191be372a794cd8d40d839ec0dbdd3c28957267dc81700' | ||
), | ||
nameMap, | ||
], | ||
]); | ||
expect(JSON.stringify(datum)).toBe(JSON.stringify(valMap)); | ||
}); | ||
}); | ||
}); | ||
|
||
describe('Value', () => { | ||
test('Simple ADA Value', () => { | ||
const val: Asset[] = [{ unit: 'lovelace', quantity: '1000000' }]; | ||
const plutusValue: Value = value(val); | ||
const assets: Asset[] = parsePlutusValueToAssets(plutusValue); | ||
|
||
expect(JSON.stringify(val)).toBe(JSON.stringify(assets)); | ||
}); | ||
test('Simple token Value', () => { | ||
const val: Asset[] = [ | ||
{ | ||
unit: 'baefdc6c5b191be372a794cd8d40d839ec0dbdd3c28957267dc8170074657374696e676e657777616c2e616461', | ||
quantity: '345', | ||
}, | ||
]; | ||
const plutusValue: Value = value(val); | ||
const assets: Asset[] = parsePlutusValueToAssets(plutusValue); | ||
|
||
expect(JSON.stringify(val)).toBe(JSON.stringify(assets)); | ||
}); | ||
test('Complex Value', () => { | ||
const val: Asset[] = [ | ||
{ unit: 'lovelace', quantity: '1000000' }, | ||
{ | ||
unit: 'baefdc6c5b191be372a794cd8d40d839ec0dbdd3c28957267dc817001234', | ||
quantity: '567', | ||
}, | ||
{ | ||
unit: 'baefdc6c5b191be372a794cd8d40d839ec0dbdd3c28957267dc8170074657374696e676e657777616c2e616461', | ||
quantity: '345', | ||
}, | ||
]; | ||
const plutusValue: Value = value(val); | ||
const assets: Asset[] = parsePlutusValueToAssets(plutusValue); | ||
expect(JSON.stringify(val)).toBe(JSON.stringify(assets)); | ||
}); | ||
}); |
Oops, something went wrong.