Skip to content

Commit

Permalink
test: run on Ceres
Browse files Browse the repository at this point in the history
  • Loading branch information
davidyuk committed Dec 6, 2023
1 parent e5f4e00 commit 9a8f53f
Show file tree
Hide file tree
Showing 7 changed files with 67 additions and 37 deletions.
2 changes: 1 addition & 1 deletion docker/aeternity_node_mean16.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ chain:
persist: false
hard_forks:
"1": 0
"5": 1
"6": 1

mining:
autostart: true
Expand Down
7 changes: 4 additions & 3 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
59 changes: 35 additions & 24 deletions test/integration/contract.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import {
genSalt,
UnexpectedTsError,
AeSdk,
Contract, ContractMethodsBase,
Contract, ContractMethodsBase, ConsensusProtocolVersion,
} from '../../src';

const identitySourceCode = `
Expand Down Expand Up @@ -295,6 +295,7 @@ describe('Contract', () => {
let contract: Contract<{
getName: (name: string) => {
'AENS.Name': [Encoded.AccountAddress, ChainTtl, Map<string, string>];
'AENSv2.Name': [Encoded.AccountAddress, ChainTtl, Map<string, string>];
};
signedPreclaim: (addr: Encoded.AccountAddress, chash: Uint8Array, sign: Uint8Array) => void;
signedClaim: (
Expand All @@ -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);
Expand Down Expand Up @@ -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);
Expand Down
6 changes: 5 additions & 1 deletion test/integration/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import {
AeSdk, CompilerHttpNode, MemoryAccount, Node, Encoded,
AeSdk, CompilerHttpNode, CompilerCli8, MemoryAccount, Node, Encoded, ConsensusProtocolVersion,
} from '../../src';
import '..';

Expand Down Expand Up @@ -36,6 +36,10 @@ export async function getSdk(accountCount = 1): Promise<AeSdk> {
_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 });
}
Expand Down
10 changes: 7 additions & 3 deletions test/integration/node.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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();
});

Expand Down
18 changes: 14 additions & 4 deletions test/integration/transaction.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -63,7 +63,10 @@ describe('Transaction', () => {
});

const contractId = 'ct_TCQVoset7Y4qEyV5tgEAJAqa2Foz8J1EXqoGpq3fB6dWH5roe';
const transactions: Array<[string, Encoded.Transaction, () => Promise<Encoded.Transaction>]> = [[
const transactions: Array<[
string, (() => Promise<Encoded.Transaction>) | Encoded.Transaction,
() => Promise<Encoded.Transaction>,
]> = [[
'spend',
'tx_+F0MAaEB4TK48d23oE5jt/qWR5pUu8UlpTGn8bwM5JISGQMGf7ChAeEyuPHdt6BOY7f6lkeaVLvFJaUxp/G8DOSSEhkDBn+wiBvBbWdOyAAAhg9e1n8oAAABhHRlc3QLK3OW',
async () => aeSdk.buildTx({
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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);
}));
Expand Down

0 comments on commit 9a8f53f

Please sign in to comment.