Skip to content

Commit 218d50e

Browse files
authored
Merge pull request #1166 from aeternity/release/8.0.0
2 parents 3d96f59 + 7bbc708 commit 218d50e

File tree

6 files changed

+56
-82
lines changed

6 files changed

+56
-82
lines changed

CHANGELOG.md

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,12 @@
1+
# [8.0.0](https://github.com/aeternity/aepp-sdk-js/compare/8.0.0-beta.2...8.0.0) (2021-05-18)
2+
3+
4+
### Bug Fixes
5+
6+
* avoid instanceof between possible not/polyfilled objects ([906ee0e](https://github.com/aeternity/aepp-sdk-js/commit/906ee0ea4eb71160c3a482ea068cbb0d857cef8f))
7+
8+
9+
110
## [8.0.0-beta.2](https://github.com/aeternity/aepp-sdk-js/compare/8.0.0-beta.1...8.0.0-beta.2) (2021-05-12)
211

312

@@ -10,7 +19,7 @@
1019
* avoid ts definitions based on broken JsDoc ([572d19f](https://github.com/aeternity/aepp-sdk-js/commit/572d19f5ae6bd549c92a1a37452c0270490b9f6e))
1120

1221

13-
# [8.0.0-beta.1](https://github.com/aeternity/aepp-sdk-js/compare/7.7.0...8.0.0-beta.1) (2021-05-6)
22+
## [8.0.0-beta.1](https://github.com/aeternity/aepp-sdk-js/compare/7.7.0...8.0.0-beta.1) (2021-05-6)
1423

1524

1625
### Important changes

package-lock.json

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@aeternity/aepp-sdk",
3-
"version": "8.0.0-beta.2",
3+
"version": "8.0.0",
44
"description": "SDK for the æternity blockchain",
55
"main": "dist/aepp-sdk.js",
66
"types": "es/index.d.ts",
@@ -106,6 +106,7 @@
106106
},
107107
"files": [
108108
"dist",
109+
"src",
109110
"es"
110111
]
111112
}

src/contract/aci/transformation.js

Lines changed: 13 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -233,25 +233,21 @@ export function transformVariant (value, generic, { bindings }) {
233233
}
234234

235235
export function transformMap (value, generic, { bindings }) {
236-
if (value instanceof Map) {
237-
value = Array.from(value.entries())
238-
}
239-
if (!Array.isArray(value) && value instanceof Object) {
240-
value = Object.entries(value)
236+
if (!Array.isArray(value)) {
237+
if (value.entries) value = Array.from(value.entries())
238+
else if (value instanceof Object) value = Object.entries(value)
241239
}
242240

243-
return `{${value
244-
.reduce(
245-
(acc, [key, value], i) => {
246-
if (i !== 0) acc += ','
247-
acc += `[${transform(generic[0], key, {
248-
bindings
249-
})}] = ${transform(generic[1], value, { bindings })}`
250-
return acc
251-
},
252-
''
253-
)
254-
}}`
241+
return [
242+
'{',
243+
value
244+
.map(([key, value]) => [
245+
`[${transform(generic[0], key, { bindings })}]`,
246+
transform(generic[1], value, { bindings })
247+
].join(' = '))
248+
.join(),
249+
'}'
250+
].join('')
255251
}
256252

257253
// FUNCTION RETURN VALUE TRANSFORMATION ↓↓↓

test/integration/contract.js

Lines changed: 28 additions & 60 deletions
Original file line numberDiff line numberDiff line change
@@ -803,7 +803,7 @@ describe('Contract', function () {
803803
})
804804
it('Valid', async () => {
805805
const { decodedResult } = await contractObject.methods.tupleFn(['test', 1])
806-
JSON.stringify(decodedResult).should.be.equal(JSON.stringify(['test', 1]))
806+
decodedResult.should.be.eql(['test', 1])
807807
})
808808
})
809809
describe('LIST', function () {
@@ -830,88 +830,57 @@ describe('Contract', function () {
830830
})
831831
it('Valid', async () => {
832832
const { decodedResult } = await contractObject.methods.listInListFn([[1, 2], [3, 4]])
833-
JSON.stringify(decodedResult).should.be.equal(JSON.stringify([[1, 2], [3, 4]]))
833+
decodedResult.should.be.eql([[1, 2], [3, 4]])
834834
})
835835
})
836+
836837
describe('MAP', function () {
838+
const address = 'ak_gvxNbZf5CuxYVfcUFoKAP4geZatWaC2Yy4jpx5vZoCKank4Gc'
839+
837840
it('Valid', async () => {
838-
const address = await contract.address()
839-
const mapArg = new Map(
840-
[
841-
[address, ['someStringV', 324]]
842-
]
843-
)
844-
const objectFromMap = Array.from(mapArg.entries()).reduce((acc, [k, v]) => ({ ...acc, [k]: v }), {})
845-
const { decodedResult } = await contractObject.methods.mapFn(objectFromMap)
846-
JSON.stringify(decodedResult).should.be.equal(JSON.stringify(Array.from(mapArg.entries())))
841+
const mapArg = new Map([[address, ['someStringV', 324]]])
842+
const { decodedResult } = await contractObject.methods.mapFn(Object.fromEntries(mapArg))
843+
decodedResult.should.be.eql(Array.from(mapArg.entries()))
847844
})
845+
848846
it('Map With Option Value', async () => {
849-
const address = await contract.address()
850-
const mapArgWithSomeValue = new Map(
851-
[
852-
[address, ['someStringV', 123]]
853-
]
854-
)
855-
const mapArgWithNoneValue = new Map(
856-
[
857-
[address, ['someStringV', undefined]]
858-
]
859-
)
860-
const returnArgWithSomeValue = new Map(
861-
[
862-
[address, ['someStringV', 123]]
863-
]
864-
)
865-
const returnArgWithNoneValue = new Map(
866-
[
867-
[address, ['someStringV', undefined]]
868-
]
869-
)
870-
const resultWithSome = await contractObject.methods.mapOptionFn(mapArgWithSomeValue)
871-
const resultWithNone = await contractObject.methods.mapOptionFn(mapArgWithNoneValue)
872-
873-
const decodedSome = resultWithSome.decodedResult
874-
875-
JSON.stringify(decodedSome).should.be.equal(JSON.stringify(Array.from(returnArgWithSomeValue.entries())))
876-
JSON.stringify(resultWithNone.decodedResult).should.be.equal(JSON.stringify(Array.from(returnArgWithNoneValue.entries())))
847+
const mapWithSomeValue = new Map([[address, ['someStringV', 123]]])
848+
const mapWithNoneValue = new Map([[address, ['someStringV', undefined]]])
849+
let result = await contractObject.methods.mapOptionFn(mapWithSomeValue)
850+
result.decodedResult.should.be.eql(Array.from(mapWithSomeValue.entries()))
851+
result = await contractObject.methods.mapOptionFn(mapWithNoneValue)
852+
result.decodedResult.should.be.eql(Array.from(mapWithNoneValue.entries()))
877853
})
854+
878855
it('Cast from string to int', async () => {
879-
const address = await contract.address()
880-
const mapArg = new Map(
881-
[
882-
[address, ['someStringV', '324']]
883-
]
884-
)
856+
const mapArg = new Map([[address, ['someStringV', '324']]])
885857
const result = await contractObject.methods.mapFn(mapArg)
886858
mapArg.set(address, ['someStringV', 324])
887-
JSON.stringify(result.decodedResult).should.be.equal(JSON.stringify(Array.from(mapArg.entries())))
859+
result.decodedResult.should.be.eql(Array.from(mapArg.entries()))
888860
})
861+
889862
it('Cast from array to map', async () => {
890-
const address = await contract.address()
891-
const mapArg =
892-
[
893-
[address, ['someStringV', 324]]
894-
]
863+
const mapArg = [[address, ['someStringV', 324]]]
895864
const { decodedResult } = await contractObject.methods.mapFn(mapArg)
896-
JSON.stringify(decodedResult).should.be.equal(JSON.stringify(mapArg))
865+
decodedResult.should.be.eql(mapArg)
897866
})
898867
})
868+
899869
describe('RECORD/STATE', function () {
900-
const objEq = (obj, obj2) => !Object.entries(obj).find(([key, val]) => JSON.stringify(obj2[key]) !== JSON.stringify(val))
901870
it('Valid Set Record (Cast from JS object)', async () => {
902871
await contractObject.methods.setRecord({ value: 'qwe', key: 1234, testOption: 'test' })
903872
const state = await contractObject.methods.getRecord()
904873

905-
objEq(state.decodedResult, { value: 'qwe', key: 1234, testOption: 'test' }).should.be.equal(true)
874+
state.decodedResult.should.be.eql({ value: 'qwe', key: 1234, testOption: 'test' })
906875
})
907876
it('Get Record(Convert to JS object)', async () => {
908877
const result = await contractObject.methods.getRecord()
909-
objEq(result.decodedResult, { value: 'qwe', key: 1234, testOption: 'test' }).should.be.equal(true)
878+
result.decodedResult.should.be.eql({ value: 'qwe', key: 1234, testOption: 'test' })
910879
})
911880
it('Get Record With Option (Convert to JS object)', async () => {
912881
await contractObject.methods.setRecord({ key: 1234, value: 'qwe', testOption: 'resolved string' })
913882
const result = await contractObject.methods.getRecord()
914-
objEq(result.decodedResult, { value: 'qwe', key: 1234, testOption: 'resolved string' }).should.be.equal(true)
883+
result.decodedResult.should.be.eql({ value: 'qwe', key: 1234, testOption: 'resolved string' })
915884
})
916885
it('Invalid value type', async () => {
917886
try {
@@ -930,7 +899,7 @@ describe('Contract', function () {
930899
it('Set Some Option List Value(Cast from JS value/Convert result to JS)', async () => {
931900
const optionRes = await contractObject.methods.listOption([[1, 'testString']])
932901

933-
JSON.stringify(optionRes.decodedResult).should.be.equal(JSON.stringify([[1, 'testString']]))
902+
optionRes.decodedResult.should.be.eql([[1, 'testString']])
934903
})
935904
it('Set None Option Value(Cast from JS value/Convert to JS)', async () => {
936905
const optionRes = await contractObject.methods.intOption(undefined)
@@ -980,7 +949,7 @@ describe('Contract', function () {
980949
})
981950
it('Valid', async () => {
982951
const res = await contractObject.methods.datTypeFn('Year')
983-
JSON.stringify(res.decodedResult).should.be.equal('"Year"')
952+
res.decodedResult.should.be.equal('Year')
984953
})
985954
})
986955
describe('Hash', function () {
@@ -1078,9 +1047,8 @@ describe('Contract', function () {
10781047
contractObject.setOptions({ skipTransformDecoded: true })
10791048
const res = await contractObject.methods.listFn([1, 2])
10801049
const decoded = await res.decode()
1081-
const decodedJSON = JSON.stringify([1, 2])
10821050
contractObject.setOptions({ skipTransformDecoded: false })
1083-
JSON.stringify(decoded).should.be.equal(decodedJSON)
1051+
decoded.should.be.eql([1, 2])
10841052
})
10851053
it('Call contract with contract type argument', async () => {
10861054
const result = await contractObject.methods.approve(0, 'ct_AUUhhVZ9de4SbeRk8ekos4vZJwMJohwW5X8KQjBMUVduUmoUh')

test/integration/txVerification.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ describe('Verify Transaction', function () {
3636
.filter(({ type }) => type === 'warning')
3737
.map(({ txKey }) => txKey)
3838

39-
JSON.stringify(WARNINGS).should.be.equals(JSON.stringify(warning))
39+
WARNINGS.should.be.eql(warning)
4040
})
4141
it('check errors', async () => {
4242
const spendTx = await client.spendTx({
@@ -60,7 +60,7 @@ describe('Verify Transaction', function () {
6060
.filter(({ type }) => type === 'error') // exclude contract vm/abi, has separated test for it
6161
.map(({ txKey }) => txKey)
6262

63-
JSON.stringify(ERRORS.filter(e => e !== 'gasPrice' && e !== 'ctVersion')).should.be.equals(JSON.stringify(error))
63+
ERRORS.filter(e => e !== 'gasPrice' && e !== 'ctVersion').should.be.eql(error)
6464
}
6565
await checkErrors(signedTxHash)
6666
await checkErrors(signedTxFull)

0 commit comments

Comments
 (0)