Skip to content

Commit

Permalink
Add support for AENSv2.pointee, AENSv2.name types
Browse files Browse the repository at this point in the history
  • Loading branch information
davidyuk committed Jan 25, 2024
1 parent 9c1dffc commit 8e9c8b8
Show file tree
Hide file tree
Showing 10 changed files with 172 additions and 1 deletion.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
### Fixed
### Added
- Add support for `bytes()` arbitrary-sized type from FATE 3.
- Add support for `AENSv2.pointee`, `AENSv2.name` types from FATE 3.
### Changed
### Deprecated
### Removed
2 changes: 2 additions & 0 deletions contracts/Test.aes
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,9 @@ main contract Test =
entrypoint test_signature(a:signature) = a
entrypoint test_ttl(a:Chain.ttl) = a
entrypoint test_pointee(a:AENS.pointee) = a
entrypoint test_pointee_v2(a:AENSv2.pointee) = a
entrypoint test_aens_name(a:AENS.name) = a
entrypoint test_aens_name_v2(a:AENSv2.name) = a
entrypoint test_ga_meta_tx(a:Chain.ga_meta_tx) = a
entrypoint test_paying_for_tx(a:Chain.paying_for_tx) = a
entrypoint test_base_tx(a:Chain.base_tx) = true
Expand Down
4 changes: 3 additions & 1 deletion src/DataFactory/VariantDataFactory.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,9 @@ const TYPES = [
'variant',
'Chain.ttl',
'AENS.pointee',
'AENS.name'
'AENSv2.pointee',
'AENS.name',
'AENSv2.name'
]

class VariantDataFactory extends BaseDataFactory {
Expand Down
26 changes: 26 additions & 0 deletions src/FateTypes.js
Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,18 @@ const FateTypeAENSPointee = () => {
return FateTypeVariant(variants)
}

const FateTypeAENSv2Pointee = () => {
const variants = [
{'AENSv2.AccountPt': [FateTypeAccountAddress()]},
{'AENSv2.OraclePt': [FateTypeAccountAddress()]},
{'AENSv2.ContractPt': [FateTypeAccountAddress()]},
{'AENSv2.ChannelPt': [FateTypeAccountAddress()]},
{'AENSv2.DataPt': [FateTypeBytes()]}, // max 1024 bytes
]

return FateTypeVariant(variants)
}

const FateTypeAENSName = () => {
const variants = [{
'AENS.Name': [
Expand All @@ -199,6 +211,18 @@ const FateTypeAENSName = () => {
return FateTypeVariant(variants)
}

const FateTypeAENSv2Name = () => {
const variants = [{
'AENSv2.Name': [
FateTypeAccountAddress(),
FateTypeChainTTL(),
FateTypeMap(FateTypeString(), FateTypeAENSv2Pointee())
]
}]

return FateTypeVariant(variants)
}

const FateTypeEvent = (variantType, topics) => {
return {
name: 'event',
Expand Down Expand Up @@ -262,7 +286,9 @@ module.exports = {
FateTypeChainPayingForTx,
FateTypeChainBaseTx,
FateTypeAENSPointee,
FateTypeAENSv2Pointee,
FateTypeAENSName,
FateTypeAENSv2Name,
FateTypeEvent,
FateTypeBls12381Fr,
FateTypeBls12381Fp,
Expand Down
10 changes: 10 additions & 0 deletions src/TypeResolver.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,9 @@ const {
FateTypeChainPayingForTx,
FateTypeChainBaseTx,
FateTypeAENSPointee,
FateTypeAENSv2Pointee,
FateTypeAENSName,
FateTypeAENSv2Name,
FateTypeBls12381Fr,
FateTypeBls12381Fp
} = require('./FateTypes')
Expand Down Expand Up @@ -135,10 +137,18 @@ class TypeResolver {
return FateTypeAENSPointee()
}

if (key === 'AENSv2.pointee') {
return FateTypeAENSv2Pointee()
}

if (key === 'AENS.name') {
return FateTypeAENSName()
}

if (key === 'AENSv2.name') {
return FateTypeAENSv2Name()
}

if (key === 'Set.set') {
return FateTypeSet(...resolvedTypes)
}
Expand Down
22 changes: 22 additions & 0 deletions tests/Decoder.js
Original file line number Diff line number Diff line change
Expand Up @@ -522,6 +522,28 @@ test('Decode singleton record (optimized)', t => {
)
})

test('Decode AENSv2.name with DataPr', t => {
t.plan(1)
t.deepEqual(
encoder.decode(
CONTRACT,
'test_aens_name_v2',
'cb_rwMAO58AoGcmh1wvzEWYjmsxUe1udTT9DCHfC0A1YAxTFxGd3/Lar4IBAQEbb4MCv60vAhlvcmFjbGWvhQEBAQEBARufAKBnJodcL8xFmI5rMVHtbnU0/Qwh3wtANWAMUxcRnd/y2iF0ZXN0IGtlea+FAQEBAQEEG58BKXRlc3QgdmFsdWUZ3wys'
),
{
'AENSv2.Name': [
'ak_nRqnePWC6yGWBmR4wfN3AvQnqbv2TizxKJdvGXj8p7YZrUZ5J',
{ FixedTTL: [180205n] },
new Map([
['oracle', { 'AENSv2.OraclePt': ['ak_nRqnePWC6yGWBmR4wfN3AvQnqbv2TizxKJdvGXj8p7YZrUZ5J'] }],
['test key', { 'AENSv2.DataPt': [Uint8Array.from(Buffer.from('test value'))] }],
]),
],
},
'test_aens_name_v2(AENSv2.Name(ak_nRqnePWC6yGWBmR4wfN3AvQnqbv2TizxKJdvGXj8p7YZrUZ5J, FixedTTL(180205), {["oracle"] = AENSv2.OraclePt(ak_nRqnePWC6yGWBmR4wfN3AvQnqbv2TizxKJdvGXj8p7YZrUZ5J), ["test key"] = AENSv2.DataPt(Bytes.to_any_size(#746573742076616c7565))}))'
)
})

test('Decode Set.set', t => {
t.plan(1)
t.deepEqual(
Expand Down
83 changes: 83 additions & 0 deletions tests/Encoder.js
Original file line number Diff line number Diff line change
Expand Up @@ -561,6 +561,65 @@ test('Encode AENS.pointee arguments', t => {
)
})

test('Encode AENSv2.pointee arguments', t => {
t.plan(5)
const encoded1 = encoder.encode(
CONTRACT,
'test_pointee_v2',
[{'AENSv2.AccountPt': ['ak_2gx9MEFxKvY9vMG5YnqnXWv1hCsX7rgnfvBLJS4aQurustR1rt']}]
)
t.is(
encoded1,
'cb_KxElnEHfG6+FAQEBAQEAG58AoN5ov+GyA+UfUjUboIf3m3go5qFA8MMUpnDHADs/9XB10byw+g==',
'test_pointee_v2(AENSv2.AccountPt(ak_2gx9MEFxKvY9vMG5YnqnXWv1hCsX7rgnfvBLJS4aQurustR1rt))'
)

const encoded2 = encoder.encode(
CONTRACT,
'test_pointee_v2',
[{'AENSv2.OraclePt': ['ak_2gx9MEFxKvY9vMG5YnqnXWv1hCsX7rgnfvBLJS4aQurustR1rt']}]
)
t.is(
encoded2,
'cb_KxElnEHfG6+FAQEBAQEBG58AoN5ov+GyA+UfUjUboIf3m3go5qFA8MMUpnDHADs/9XB1XO0VzQ==',
'test_pointee_v2(AENSv2.OraclePt(ak_2gx9MEFxKvY9vMG5YnqnXWv1hCsX7rgnfvBLJS4aQurustR1rt))'
)

const encoded3 = encoder.encode(
CONTRACT,
'test_pointee_v2',
[{'AENSv2.ContractPt': ['ak_2gx9MEFxKvY9vMG5YnqnXWv1hCsX7rgnfvBLJS4aQurustR1rt']}]
)
t.is(
encoded3,
'cb_KxElnEHfG6+FAQEBAQECG58AoN5ov+GyA+UfUjUboIf3m3go5qFA8MMUpnDHADs/9XB1UFjoyQ==',
'test_pointee_v2(AENSv2.ContractPt(ak_2gx9MEFxKvY9vMG5YnqnXWv1hCsX7rgnfvBLJS4aQurustR1rt))'
)

const encoded4 = encoder.encode(
CONTRACT,
'test_pointee_v2',
[{'AENSv2.ChannelPt': ['ak_2gx9MEFxKvY9vMG5YnqnXWv1hCsX7rgnfvBLJS4aQurustR1rt']}]
)
t.is(
encoded4,
'cb_KxElnEHfG6+FAQEBAQEDG58AoN5ov+GyA+UfUjUboIf3m3go5qFA8MMUpnDHADs/9XB1547G3Q==',
'test_pointee_v2(AENSv2.ChannelPt(ak_2gx9MEFxKvY9vMG5YnqnXWv1hCsX7rgnfvBLJS4aQurustR1rt))'
)

const dataPt = Buffer.from('http://example.com')
const encoded5 = encoder.encode(
CONTRACT,
'test_pointee_v2',
[{'AENSv2.DataPt': [dataPt]}]
)
t.is(
encoded5,
'cb_KxElnEHfG6+FAQEBAQEEG58BSWh0dHA6Ly9leGFtcGxlLmNvbYixc9Q=',
`test_pointee_v2(AENSv2.DataPt(Bytes.to_any_size(#${dataPt.toString('hex')})))`
)
})

test('Encode AENS.name arguments', t => {
t.plan(1)
const encoded1 = encoder.encode(
Expand All @@ -585,6 +644,30 @@ test('Encode AENS.name arguments', t => {
)
})

test('Encode AENSv2.name arguments', t => {
t.plan(1)
const encoded1 = encoder.encode(
CONTRACT,
'test_aens_name_v2',
[
{
'AENSv2.Name': [
'ak_2gx9MEFxKvY9vMG5YnqnXWv1hCsX7rgnfvBLJS4aQurustR1rt',
{FixedTTL: [100]},
new Map([
["pt1", {'AENSv2.AccountPt': ['ak_2dATVcZ9KJU5a8hdsVtTv21pYiGWiPbmVcU1Pz72FFqpk9pSRR']}]
])
]
}
]
)
t.is(
encoded1,
'cb_KxFjVV5kG68DADufAKDeaL/hsgPlH1I1G6CH95t4KOahQPDDFKZwxwA7P/Vwda+CAQEBG28kLwENcHQxr4UBAQEBAQAbnwCg1c8IQA6YgiLybrSwLI+JB3RXRnIRpubZVe23B0nGoztVU63L',
'test_aens_name_v2(AENSv2.Name(ak_2gx9MEFxKvY9vMG5YnqnXWv1hCsX7rgnfvBLJS4aQurustR1rt, RelativeTTL(100), {["pt1"] = AENSv2.AccountPt(ak_2dATVcZ9KJU5a8hdsVtTv21pYiGWiPbmVcU1Pz72FFqpk9pSRR)}))'
)
})

test('Encode Chain.ga_meta_tx arguments', t => {
t.plan(1)
const encoded1 = encoder.encode(
Expand Down
18 changes: 18 additions & 0 deletions tests/TypeResolver.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,9 @@ const {
FateTypeChainPayingForTx,
FateTypeChainBaseTx,
FateTypeAENSPointee,
FateTypeAENSv2Pointee,
FateTypeAENSName,
FateTypeAENSv2Name,
FateTypeSet,
FateTypeBls12381Fr,
FateTypeBls12381Fp,
Expand Down Expand Up @@ -336,6 +338,14 @@ test('Resolve AENS.pointee', t => {
)
})

test('Resolve AENSv2.pointee', t => {
t.plan(1)
t.deepEqual(
resolver.resolveType('AENSv2.pointee'),
FateTypeAENSv2Pointee()
)
})

test('Resolve AENS.name', t => {
t.plan(1)
t.deepEqual(
Expand All @@ -344,6 +354,14 @@ test('Resolve AENS.name', t => {
)
})

test('Resolve AENSv2.name', t => {
t.plan(1)
t.deepEqual(
resolver.resolveType('AENSv2.name'),
FateTypeAENSv2Name()
)
})

test('Resolve Set.set', t => {
t.plan(1)
t.deepEqual(
Expand Down
1 change: 1 addition & 0 deletions tests/integration/decoder.sh
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ test_decoder 'test_primitives_tuple' 'cb_ewL/EXRlc3RPAJ8BCb7vnwGBAAECAwQFBgcICQo
test_decoder 'test_addresses_tuple' 'cb_S58AoN5ov+GyA+UfUjUboIf3m3go5qFA8MMUpnDHADs/9XB1nwKgH8DQmexaE8uTKKMX/OzYUrH3SJ5eALoJVzw8LbaYVVOfA6DK8iokTtrAPSbwKhfZI5QtBVz8hiMoslpRwoS8nUIOSZ8EoO0e59wCeNBc6VCUc8UKk9Q6KLKNUDL2332qRC/hNxNI/pLnKw=='
test_decoder 'test_complex_tuple' 'cb_WysCAq+EAAABAAIbBjMCBAYvAgIEBggrCgyRsE4R'
test_decoder 'test_set' 'cb_LwQKPxA/Gj8qPwZjWoo='
test_decoder 'test_aens_name_v2' 'cb_rwMAO58AoGcmh1wvzEWYjmsxUe1udTT9DCHfC0A1YAxTFxGd3/Lar4IBAQEbb4MCv60vAhlvcmFjbGWvhQEBAQEBARufAKBnJodcL8xFmI5rMVHtbnU0/Qwh3wtANWAMUxcRnd/y2iF0ZXN0IGtlea+FAQEBAQEEG58BKXRlc3QgdmFsdWUZ3wys'
# https://github.com/aeternity/aesophia_cli/issues/61
# test_decoder 'test_bls12_381_fr' 'cb_nwGBxHFEFDqOu+s9/hWhDQxmnzSFvfQ6dkSwETqb5Rgy7EblqaTu'
# test_decoder 'test_bls12_381_fp' 'cb_nwHBA/Xt2rba+aow52i/Vr/nGSDbg1ErD/oOVs0LOV1F83sEMEfueZoY+Ng3idzNLTcU1fPMEQ=='
Expand Down
6 changes: 6 additions & 0 deletions tests/integration/encoder.sh
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,13 @@ test_encoder 'test_pointee(AENS.AccountPt(ak_2gx9MEFxKvY9vMG5YnqnXWv1hCsX7rgnfvB
test_encoder 'test_pointee(AENS.OraclePt(ak_2gx9MEFxKvY9vMG5YnqnXWv1hCsX7rgnfvBLJS4aQurustR1rt))'
test_encoder 'test_pointee(AENS.ContractPt(ak_2gx9MEFxKvY9vMG5YnqnXWv1hCsX7rgnfvBLJS4aQurustR1rt))'
test_encoder 'test_pointee(AENS.ChannelPt(ak_2gx9MEFxKvY9vMG5YnqnXWv1hCsX7rgnfvBLJS4aQurustR1rt))'
test_encoder 'test_pointee_v2(AENSv2.AccountPt(ak_2gx9MEFxKvY9vMG5YnqnXWv1hCsX7rgnfvBLJS4aQurustR1rt))'
test_encoder 'test_pointee_v2(AENSv2.OraclePt(ak_2gx9MEFxKvY9vMG5YnqnXWv1hCsX7rgnfvBLJS4aQurustR1rt))'
test_encoder 'test_pointee_v2(AENSv2.ContractPt(ak_2gx9MEFxKvY9vMG5YnqnXWv1hCsX7rgnfvBLJS4aQurustR1rt))'
test_encoder 'test_pointee_v2(AENSv2.ChannelPt(ak_2gx9MEFxKvY9vMG5YnqnXWv1hCsX7rgnfvBLJS4aQurustR1rt))'
test_encoder 'test_pointee_v2(AENSv2.DataPt(Bytes.to_any_size(#687474703a2f2f6578616d706c652e636f6d)))'
test_encoder 'test_aens_name(AENS.Name(ak_2gx9MEFxKvY9vMG5YnqnXWv1hCsX7rgnfvBLJS4aQurustR1rt, FixedTTL(100), {["pt1"] = AENS.AccountPt(ak_2dATVcZ9KJU5a8hdsVtTv21pYiGWiPbmVcU1Pz72FFqpk9pSRR)}))'
test_encoder 'test_aens_name_v2(AENSv2.Name(ak_2gx9MEFxKvY9vMG5YnqnXWv1hCsX7rgnfvBLJS4aQurustR1rt, FixedTTL(100), {["pt1"] = AENSv2.AccountPt(ak_2dATVcZ9KJU5a8hdsVtTv21pYiGWiPbmVcU1Pz72FFqpk9pSRR)}))'
test_encoder 'test_ga_meta_tx(Chain.GAMetaTx(ak_2gx9MEFxKvY9vMG5YnqnXWv1hCsX7rgnfvBLJS4aQurustR1rt, 42))'
test_encoder 'test_paying_for_tx(Chain.PayingForTx(ak_2gx9MEFxKvY9vMG5YnqnXWv1hCsX7rgnfvBLJS4aQurustR1rt, 42))'
test_encoder 'test_base_tx(Chain.SpendTx(ak_2gx9MEFxKvY9vMG5YnqnXWv1hCsX7rgnfvBLJS4aQurustR1rt, 42, "foo"))'
Expand Down

0 comments on commit 8e9c8b8

Please sign in to comment.