From 9a8f53fba865d610f200ab5d73d3f6237d46dfa5 Mon Sep 17 00:00:00 2001 From: Denis Davidyuk Date: Sun, 19 Nov 2023 12:43:28 +0530 Subject: [PATCH] test: run on Ceres --- docker/aeternity_node_mean16.yaml | 2 +- package-lock.json | 7 ++-- package.json | 2 +- test/integration/contract.ts | 59 ++++++++++++++++++------------- test/integration/index.ts | 6 +++- test/integration/node.ts | 10 ++++-- test/integration/transaction.ts | 18 +++++++--- 7 files changed, 67 insertions(+), 37 deletions(-) diff --git a/docker/aeternity_node_mean16.yaml b/docker/aeternity_node_mean16.yaml index 99002e4519..30160fcee7 100644 --- a/docker/aeternity_node_mean16.yaml +++ b/docker/aeternity_node_mean16.yaml @@ -19,7 +19,7 @@ chain: persist: false hard_forks: "1": 0 - "5": 1 + "6": 1 mining: autostart: true diff --git a/package-lock.json b/package-lock.json index bffed057ec..63b454287c 100644 --- a/package-lock.json +++ b/package-lock.json @@ -9,7 +9,7 @@ "version": "13.2.2", "license": "ISC", "dependencies": { - "@aeternity/aepp-calldata": "^1.5.1", + "@aeternity/aepp-calldata": "github:aeternity/aepp-calldata-js#7cce0a6d23ec0ba5f23f46acf9d4254a9346c9c9", "@aeternity/argon2": "^0.0.1", "@aeternity/uuid": "^0.0.1", "@azure/core-client": "1.6.0", @@ -106,8 +106,9 @@ }, "node_modules/@aeternity/aepp-calldata": { "version": "1.5.1", - "resolved": "https://registry.npmjs.org/@aeternity/aepp-calldata/-/aepp-calldata-1.5.1.tgz", - "integrity": "sha512-D477egpY0ErwquDOhLfCozCRaEDwRE8Vtrc2DR92dU7dkGHGp5zSikZU+cy060UaDmV4eXbU9oV8ch4ryFDqBw==", + "resolved": "git+ssh://git@github.com/aeternity/aepp-calldata-js.git#7cce0a6d23ec0ba5f23f46acf9d4254a9346c9c9", + "integrity": "sha512-n93g11FUxWtz9HBS/eY93B4imtkN2b4YpVChsWPQv10hrr9cLy+T7s/a7d5vW5/j/GrqEOGaTRfFpUi8kze6Uw==", + "license": "ISC", "dependencies": { "blakejs": "^1.2.1", "bs58": "^5.0.0", diff --git a/package.json b/package.json index 52e72b6628..ebbe4eb7c3 100644 --- a/package.json +++ b/package.json @@ -75,7 +75,7 @@ "SDK" ], "dependencies": { - "@aeternity/aepp-calldata": "^1.5.1", + "@aeternity/aepp-calldata": "github:aeternity/aepp-calldata-js#7cce0a6d23ec0ba5f23f46acf9d4254a9346c9c9", "@aeternity/argon2": "^0.0.1", "@aeternity/uuid": "^0.0.1", "@azure/core-client": "1.6.0", diff --git a/test/integration/contract.ts b/test/integration/contract.ts index a387427f47..0ebbedb6b1 100644 --- a/test/integration/contract.ts +++ b/test/integration/contract.ts @@ -14,7 +14,7 @@ import { genSalt, UnexpectedTsError, AeSdk, - Contract, ContractMethodsBase, + Contract, ContractMethodsBase, ConsensusProtocolVersion, } from '../../src'; const identitySourceCode = ` @@ -295,6 +295,7 @@ describe('Contract', () => { let contract: Contract<{ getName: (name: string) => { 'AENS.Name': [Encoded.AccountAddress, ChainTtl, Map]; + 'AENSv2.Name': [Encoded.AccountAddress, ChainTtl, Map]; }; signedPreclaim: (addr: Encoded.AccountAddress, chash: Uint8Array, sign: Uint8Array) => void; signedClaim: ( @@ -315,34 +316,44 @@ describe('Contract', () => { owner: Encoded.AccountAddress, name: string, key: string, - pt: { 'AENS.OraclePt': readonly [Encoded.Any] }, + pt: { + 'AENS.OraclePt'?: readonly [Encoded.Any]; + 'AENSv2.OraclePt'?: readonly [Encoded.Any]; + }, sign: Uint8Array ) => void; }>; let contractAddress: Encoded.ContractAddress; + let aens: string; before(async () => { + const isIris = (await aeSdk.api.getNodeInfo()) + .consensusProtocolVersion === ConsensusProtocolVersion.Iris; + aens = isIris ? 'AENS' : 'AENSv2'; contract = await aeSdk.initializeContract({ - sourceCode: - 'contract DelegateTest =\n' - + ' entrypoint getName(name: string): option(AENS.name) =\n' - + ' AENS.lookup(name)\n' - + ' stateful payable entrypoint signedPreclaim(addr: address, chash: hash, sign: signature): unit =\n' - + ' AENS.preclaim(addr, chash, signature = sign)\n' - + ' stateful entrypoint signedClaim(\n' - + ' addr: address, name: string, salt: int, name_fee: int, sign: signature): unit =\n' - + ' AENS.claim(addr, name, salt, name_fee, signature = sign)\n' - + ' stateful entrypoint signedTransfer(\n' - + ' owner: address, new_owner: address, name: string, sign: signature): unit =\n' - + ' AENS.transfer(owner, new_owner, name, signature = sign)\n' - + ' stateful entrypoint signedRevoke(owner: address, name: string, sign: signature): unit =\n' - + ' AENS.revoke(owner, name, signature = sign)\n' - + ' stateful entrypoint signedUpdate(\n' - + ' owner: address, name: string, key: string, pt: AENS.pointee, sig: signature) =\n' - + ' switch(AENS.lookup(name))\n' - + ' None => ()\n' - + ' Some(AENS.Name(_, _, ptrs)) =>\n' - + ' AENS.update(owner, name, None, None, Some(ptrs{[key] = pt}), signature = sig)', + sourceCode: ` +@compiler ${isIris ? '>= 7' : '>= 8'} +@compiler ${isIris ? '< 8' : '< 9'} + +contract DelegateTest = + entrypoint getName(name: string): option(${aens}.name) = + ${aens}.lookup(name) + stateful payable entrypoint signedPreclaim(addr: address, chash: hash, sign: signature): unit = + ${aens}.preclaim(addr, chash, signature = sign) + stateful entrypoint signedClaim( + addr: address, name: string, salt: int, name_fee: int, sign: signature): unit = + ${aens}.claim(addr, name, salt, name_fee, signature = sign) + stateful entrypoint signedTransfer( + owner: address, new_owner: address, name: string, sign: signature): unit = + ${aens}.transfer(owner, new_owner, name, signature = sign) + stateful entrypoint signedRevoke(owner: address, name: string, sign: signature): unit = + ${aens}.revoke(owner, name, signature = sign) + stateful entrypoint signedUpdate( + owner: address, name: string, key: string, pt: ${aens}.pointee, sig: signature) = + switch(${aens}.lookup(name)) + None => () + Some(${aens}.Name(_, _, ptrs)) => + ${aens}.update(owner, name, None, None, Some(ptrs{[key] = pt}), signature = sig)`, }); await contract.$deploy([]); assertNotNull(contract.$options.address); @@ -372,14 +383,14 @@ describe('Contract', () => { }); it('gets', async () => { - const nameEntry = (await contract.getName(name)).decodedResult['AENS.Name']; + const nameEntry = (await contract.getName(name)).decodedResult[`${aens}.Name`]; expect(nameEntry[0]).to.be.equal(owner); expect(nameEntry[1].FixedTTL[0]).to.be.a('bigint'); expect(nameEntry[2]).to.be.eql(new Map()); }); it('updates', async () => { - const pointee = { 'AENS.OraclePt': [newOwner] as const }; + const pointee = { [`${aens}.OraclePt`]: [newOwner] as const }; const { result } = await contract .signedUpdate(owner, name, 'oracle', pointee, delegationSignature); assertNotNull(result); diff --git a/test/integration/index.ts b/test/integration/index.ts index 46882de5c9..1a83eb8786 100644 --- a/test/integration/index.ts +++ b/test/integration/index.ts @@ -1,5 +1,5 @@ import { - AeSdk, CompilerHttpNode, MemoryAccount, Node, Encoded, + AeSdk, CompilerHttpNode, CompilerCli8, MemoryAccount, Node, Encoded, ConsensusProtocolVersion, } from '../../src'; import '..'; @@ -36,6 +36,10 @@ export async function getSdk(accountCount = 1): Promise { _expectedMineRate: 1000, _microBlockCycle: 300, }); + // TODO: remove after release aesophia_http@8 + if ((await sdk.api.getNodeInfo()).consensusProtocolVersion === ConsensusProtocolVersion.Ceres) { + sdk._options.onCompiler = new CompilerCli8(); + } for (let i = 0; i < accounts.length; i += 1) { await sdk.spend(1e32, accounts[i].address, { onAccount: genesisAccount }); } diff --git a/test/integration/node.ts b/test/integration/node.ts index 2beac10709..ef332f717f 100644 --- a/test/integration/node.ts +++ b/test/integration/node.ts @@ -53,10 +53,14 @@ describe('Node client', () => { it('throws exception if unsupported protocol', async () => { const sandbox = createSandbox(); - sandbox.stub(ConsensusProtocolVersion, 'Iris').value(undefined); - sandbox.stub(ConsensusProtocolVersion, '5' as 'Iris').value(undefined); + const [name, version, message] = { + 5: ['Iris', '5', '5. Supported: >= 6 < 7'], + 6: ['Ceres', '6', '6. Supported: >= 5 < 6'], + }[(await node.getNodeInfo()).consensusProtocolVersion]; + sandbox.stub(ConsensusProtocolVersion, name as any).value(undefined); + sandbox.stub(ConsensusProtocolVersion, version as any).value(undefined); await expect(node.getNodeInfo()).to.be - .rejectedWith('Unsupported consensus protocol version 5. Supported: >= 6 < 7'); + .rejectedWith(`Unsupported consensus protocol version ${message}`); sandbox.restore(); }); diff --git a/test/integration/transaction.ts b/test/integration/transaction.ts index dd7b7fa1d1..5473a7b4d8 100644 --- a/test/integration/transaction.ts +++ b/test/integration/transaction.ts @@ -4,7 +4,7 @@ import { getSdk } from './index'; import { AeSdk, Contract, commitmentHash, oracleQueryId, decode, encode, Encoded, Encoding, - ORACLE_TTL_TYPES, Tag, AE_AMOUNT_FORMATS, buildTx, unpackTx, + ORACLE_TTL_TYPES, Tag, AE_AMOUNT_FORMATS, buildTx, unpackTx, ConsensusProtocolVersion, } from '../../src'; const nonce = 1; @@ -63,7 +63,10 @@ describe('Transaction', () => { }); const contractId = 'ct_TCQVoset7Y4qEyV5tgEAJAqa2Foz8J1EXqoGpq3fB6dWH5roe'; - const transactions: Array<[string, Encoded.Transaction, () => Promise]> = [[ + const transactions: Array<[ + string, (() => Promise) | Encoded.Transaction, + () => Promise, + ]> = [[ 'spend', 'tx_+F0MAaEB4TK48d23oE5jt/qWR5pUu8UlpTGn8bwM5JISGQMGf7ChAeEyuPHdt6BOY7f6lkeaVLvFJaUxp/G8DOSSEhkDBn+wiBvBbWdOyAAAhg9e1n8oAAABhHRlc3QLK3OW', async () => aeSdk.buildTx({ @@ -107,7 +110,13 @@ describe('Transaction', () => { }), ], [ 'contract create', - 'tx_+LAqAaEBhAyXS5cWR3ZFS6EZ2E7cTWBYqN7JK27cV4qy0wtMQgABuGr4aEYDoKEijZbj/w2AeiWwAbldusME5pm3ZgPuomnZ3TbUbYgrwLg7nv5E1kQfADcANwAaDoI/AQM//oB4IJIANwEHBwEBAJgvAhFE1kQfEWluaXQRgHggkhlnZXRBcmeCLwCFNy40LjAAgwcAA4ZHcyzkwAAAAACDTEtAhDuaygCHKxFE1kQfPz3ZtIU=', + async () => { + const { consensusProtocolVersion } = await aeSdk.api.getNodeInfo(); + if (consensusProtocolVersion === ConsensusProtocolVersion.Iris) { + return 'tx_+LAqAaEBhAyXS5cWR3ZFS6EZ2E7cTWBYqN7JK27cV4qy0wtMQgABuGr4aEYDoKEijZbj/w2AeiWwAbldusME5pm3ZgPuomnZ3TbUbYgrwLg7nv5E1kQfADcANwAaDoI/AQM//oB4IJIANwEHBwEBAJgvAhFE1kQfEWluaXQRgHggkhlnZXRBcmeCLwCFNy40LjAAgwcAA4ZHcyzkwAAAAACDTEtAhDuaygCHKxFE1kQfPz3ZtIU='; + } + return 'tx_+LAqAaEBhAyXS5cWR3ZFS6EZ2E7cTWBYqN7JK27cV4qy0wtMQgABuGr4aEYDoKEijZbj/w2AeiWwAbldusME5pm3ZgPuomnZ3TbUbYgrwLg7nv5E1kQfADcANwAaDoI/AQM//oB4IJIANwEHBwEBAJgvAhFE1kQfEWluaXQRgHggkhlnZXRBcmeCLwCFOC4wLjAAgwgAA4ZHcyzkwAAAAACDTEtAhDuaygCHKxFE1kQfP6UPXo4='; + }, async () => aeSdk.buildTx({ tag: Tag.ContractCreateTx, nonce, @@ -173,7 +182,8 @@ describe('Transaction', () => { }), ]]; - transactions.forEach(([txName, expected, getter]) => it(`build of ${txName} transaction`, async () => { + transactions.forEach(([txName, getExpected, getter]) => it(`build of ${txName} transaction`, async () => { + const expected = typeof getExpected === 'function' ? await getExpected() : getExpected; expect(await getter()).to.be.equal(expected); expect(buildTx(unpackTx(expected))).to.be.equal(expected); }));