Skip to content

Commit

Permalink
Merge branch 'ccd-js-gen-use-schema' into api-strict-types
Browse files Browse the repository at this point in the history
  • Loading branch information
limemloh committed Sep 26, 2023
2 parents 0e927b2 + b528f5a commit 8545066
Show file tree
Hide file tree
Showing 15 changed files with 140 additions and 107 deletions.
9 changes: 4 additions & 5 deletions .github/workflows/pipeline.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,16 @@ name: Build, lint and typecheck examples
on:
# Triggers the workflow on push or pull request events but only for the main branch
push:
branches: [ main, release** ]
branches: [main, release**]
pull_request:
branches: [ main, release** ]
branches: [main, release**]
# Don't run on draft PR's, see: https://github.com/orgs/community/discussions/25722#discussioncomment-3248917
types: [ opened, synchronize, reopened, ready_for_review ]
types: [opened, synchronize, reopened, ready_for_review]
# Allows us to run the workflow manually from the Actions tab
workflow_dispatch:


env:
DUMMY: 1
DUMMY: 1 # For cache busting.
NODE_VERSION: 18.16.0
RUST_VERSION: 1.65
RUST_FMT: nightly-2023-04-01-x86_64-unknown-linux-gnu
Expand Down
4 changes: 3 additions & 1 deletion docs/pages/misc-pages/upgrade-guide.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@

### Common

Several types have been replaced with a module containing the type itself together with functions for constructing and converting the type:
Several types have been replaced with a module containing the type itself together with functions for constructing and
converting the type:

- `AccountAddress` is now a module with functions related to account addresses:
- To refer to `AccountAddress` as a type use `AccountAddress.Type`.
- Constructing `new AccountAddress("<address>")` is now `AccountAddress.fromBase58("<address>")`.
Expand Down
2 changes: 1 addition & 1 deletion packages/common/src/cis2/CIS2Contract.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { stringify } from 'json-bigint';

import { HexString, InvokeContractResult } from '../types.js';
import type { HexString, InvokeContractResult } from '../types.js';
import * as ContractAddress from '../types/ContractAddress.js';
import * as BlockHash from '../types/BlockHash.js';
import * as TransactionHash from '../types/TransactionHash.js';
Expand Down
14 changes: 7 additions & 7 deletions packages/common/test/alias.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import * as AccountAddress from '../src/types/AccountAddress.js';
test('isAlias is reflexive', () => {
const address = AccountAddress.fromBuffer(
Buffer.from(
'01e718721402249e81f8fedcba6027f1c9bcb4445e9433b7905d579d83ec000002',
'e718721402249e81f8fedcba6027f1c9bcb4445e9433b7905d579d83ec000002',
'hex'
)
);
Expand All @@ -13,13 +13,13 @@ test('isAlias is reflexive', () => {
test('isAlias: Addresses with first 29 bytes in common are aliases', () => {
const address = AccountAddress.fromBuffer(
Buffer.from(
'01e718721402249e81f8fedcba6027f1c9bcb4445e9433b7905d579d83ec000002',
'e718721402249e81f8fedcba6027f1c9bcb4445e9433b7905d579d83ec000002',
'hex'
)
);
const alias = AccountAddress.fromBuffer(
Buffer.from(
'01e718721402249e81f8fedcba6027f1c9bcb4445e9433b7905d579d83ececb467',
'e718721402249e81f8fedcba6027f1c9bcb4445e9433b7905d579d83ececb467',
'hex'
)
);
Expand All @@ -29,13 +29,13 @@ test('isAlias: Addresses with first 29 bytes in common are aliases', () => {
test('isAlias: Addresses with differences in the 5th byte are not aliases', () => {
const address = AccountAddress.fromBuffer(
Buffer.from(
'01e718721412249e81f8fedcba6027f1c9bcb4445e9433b7905d579d83ec000002',
'e718721412249e81f8fedcba6027f1c9bcb4445e9433b7905d579d83ec000002',
'hex'
)
);
const alias = AccountAddress.fromBuffer(
Buffer.from(
'01e718721402249e81f8fedcba6027f1c9bcb4445e9433b7905d579d83ec000002',
'e718721402249e81f8fedcba6027f1c9bcb4445e9433b7905d579d83ec000002',
'hex'
)
);
Expand All @@ -45,13 +45,13 @@ test('isAlias: Addresses with differences in the 5th byte are not aliases', () =
test('isAlias: Addresses with differences in the 29th byte are not aliases', () => {
const address = AccountAddress.fromBuffer(
Buffer.from(
'01e718721402249e81f8fedcba6027f1c9bcb4445e9433b7905d579d83ececb467',
'e718721402249e81f8fedcba6027f1c9bcb4445e9433b7905d579d83ececb467',
'hex'
)
);
const alias = AccountAddress.fromBuffer(
Buffer.from(
'01e718721402249e81f8fedcba6027f1c9bcb4445e9433b7905d579d83e1ecb467',
'e718721402249e81f8fedcba6027f1c9bcb4445e9433b7905d579d83e1ecb467',
'hex'
)
);
Expand Down
8 changes: 4 additions & 4 deletions packages/common/test/deserialization.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ function deserializeAccountTransactionBase(
const header: AccountTransactionHeader = {
expiry,
nonce: 0n,
sender: new AccountAddress(
sender: AccountAddress.fromBase58(
'3VwCfvVskERFAJ3GeJy2mNFrzfChqUymSJJCvoLAP9rtAwMGYt'
),
};
Expand Down Expand Up @@ -60,7 +60,7 @@ function deserializeAccountTransactionBase(
test('test deserialize simpleTransfer ', () => {
const payload: SimpleTransferPayload = {
amount: new CcdAmount(5100000n),
toAddress: new AccountAddress(
toAddress: AccountAddress.fromBase58(
'3VwCfvVskERFAJ3GeJy2mNFrzfChqUymSJJCvoLAP9rtAwMGYt'
),
};
Expand All @@ -70,7 +70,7 @@ test('test deserialize simpleTransfer ', () => {
test('test deserialize simpleTransfer with memo ', () => {
const payload: SimpleTransferWithMemoPayload = {
amount: new CcdAmount(5100000n),
toAddress: new AccountAddress(
toAddress: AccountAddress.fromBase58(
'3VwCfvVskERFAJ3GeJy2mNFrzfChqUymSJJCvoLAP9rtAwMGYt'
),
memo: new DataBlob(Buffer.from('00', 'hex')),
Expand All @@ -94,7 +94,7 @@ test('test deserialize registerData ', () => {
test('Expired transactions can be deserialized', () => {
const payload: SimpleTransferPayload = {
amount: new CcdAmount(5100000n),
toAddress: new AccountAddress(
toAddress: AccountAddress.fromBase58(
'3VwCfvVskERFAJ3GeJy2mNFrzfChqUymSJJCvoLAP9rtAwMGYt'
),
};
Expand Down
4 changes: 2 additions & 2 deletions packages/common/test/signHelpers.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -76,14 +76,14 @@ const testEachMessageType = test.each(['test', Buffer.from('test', 'utf8')]);
testEachMessageType('[%o] test signMessage', async (message) => {
const sign = () => signMessage(account, message, signer);

let account = new AccountAddress(TEST_ACCOUNT_SINGLE);
let account = AccountAddress.fromBase58(TEST_ACCOUNT_SINGLE);
let signer = buildBasicAccountSigner(TEST_KEY_SINGLE);
let signature = await sign();
expect(signature[0][0]).toBe(
'445197d79ca90d8cc8440328dac9f307932ade0c03cc7aa575b59b746e26e5f1bca13ade5ff7a56e918ba5a32450fdf52b034cd2580929b21213263e81f7f809'
);

account = new AccountAddress(TEST_ACCOUNT_MULTI);
account = AccountAddress.fromBase58(TEST_ACCOUNT_MULTI);
signer = buildAccountSigner(TEST_KEYS_MULTI);
signature = await sign();

Expand Down
2 changes: 0 additions & 2 deletions packages/nodejs/src/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -783,8 +783,6 @@ export default class ConcordiumNodeClient {
'allPoolTotalCapital',
];

// const response = await this.sendRequest(this.client.getPoolStatus, req);

return convertJsonResponse<PoolStatus>(
value,
buildJsonResponseReviver(dates, bigInts),
Expand Down
77 changes: 47 additions & 30 deletions packages/nodejs/test/CIS2Contract.test.ts
Original file line number Diff line number Diff line change
@@ -1,35 +1,33 @@
import {
AccountAddress,
AccountTransactionType,
ContractAddress,
EntrypointName,
TransactionEventTag,
} from '@concordium/common-sdk';
import { getNodeClientV2 as getNodeClient } from './testHelpers.js';
import { CIS2Contract } from '@concordium/common-sdk/cis2';
import { serializeTypeValue } from '@concordium/common-sdk/schema';

const CIS2_FT_ADDRESS: ContractAddress = {
index: 3496n,
subindex: 0n,
};
const CIS2_NFT_ADDRESS: ContractAddress = {
index: 1696n,
subindex: 0n,
};
const CIS2_FT_ADDRESS = ContractAddress.create(3496);
const CIS2_NFT_ADDRESS = ContractAddress.create(1696);

const TEST_BLOCK =
'3e9d90325c61ab190065f3c90364beeb925833319de68d982ec6da7762e8357b';
const TEST_ACCOUNT = '4UC8o4m8AgTxt5VBFMdLwMCwwJQVJwjesNzW7RPXkACynrULmd';
const TEST_ACCOUNT = AccountAddress.fromBase58(
'4UC8o4m8AgTxt5VBFMdLwMCwwJQVJwjesNzW7RPXkACynrULmd'
);

const getCIS2Single = () =>
CIS2Contract.create(getNodeClient(), CIS2_FT_ADDRESS);
const getCIS2Multi = () =>
CIS2Contract.create(getNodeClient(), CIS2_NFT_ADDRESS);

test('create throws on non cis-2', async () => {
const promise = CIS2Contract.create(getNodeClient(), {
index: 3494n,
subindex: 0n,
});
const promise = CIS2Contract.create(
getNodeClient(),
ContractAddress.create(3494)
);
expect(promise).rejects.toThrow();
});

Expand All @@ -55,7 +53,7 @@ test('balanceOf', async () => {
test('operatorOf', async () => {
const cis2Single = await getCIS2Single();
const isOperator = await cis2Single.operatorOf(
{ owner: TEST_ACCOUNT, address: { index: 3494n, subindex: 0n } },
{ owner: TEST_ACCOUNT, address: ContractAddress.create(3494) },
TEST_BLOCK
);
expect(isOperator).toEqual(true);
Expand All @@ -65,9 +63,11 @@ test('operatorOf', async () => {
[
{
owner: TEST_ACCOUNT,
address: '3ybJ66spZ2xdWF3avgxQb2meouYa7mpvMWNPmUnczU8FoF8cGB',
address: AccountAddress.fromBase58(
'3ybJ66spZ2xdWF3avgxQb2meouYa7mpvMWNPmUnczU8FoF8cGB'
),
},
{ owner: TEST_ACCOUNT, address: { index: 3494n, subindex: 0n } },
{ owner: TEST_ACCOUNT, address: ContractAddress.create(3494) },
],
TEST_BLOCK
);
Expand Down Expand Up @@ -123,13 +123,17 @@ test('dryRun.transfer', async () => {
{
tokenId: '',
from: TEST_ACCOUNT,
to: '3ybJ66spZ2xdWF3avgxQb2meouYa7mpvMWNPmUnczU8FoF8cGB',
to: AccountAddress.fromBase58(
'3ybJ66spZ2xdWF3avgxQb2meouYa7mpvMWNPmUnczU8FoF8cGB'
),
tokenAmount: 100n,
},
{
tokenId: '',
from: TEST_ACCOUNT,
to: '4owvMHZSKsPW8QGYUEWSdgqxfoPBh3ZwPameBV46pSvmeHDkEe',
to: AccountAddress.fromBase58(
'4owvMHZSKsPW8QGYUEWSdgqxfoPBh3ZwPameBV46pSvmeHDkEe'
),
tokenAmount: 120n,
},
],
Expand All @@ -150,8 +154,8 @@ test('dryRun.transfer', async () => {
tokenId: '',
from: TEST_ACCOUNT,
to: {
address: { index: 4416n, subindex: 0n },
hookName: 'onReceivingCIS2',
address: ContractAddress.create(4416),
hookName: EntrypointName.fromStringUnchecked('onReceivingCIS2'),
},
tokenAmount: 0n,
},
Expand All @@ -167,7 +171,9 @@ describe('createTransfer', () => {
{ energy: 1000000n },
{
tokenId: '',
to: '3ybJ66spZ2xdWF3avgxQb2meouYa7mpvMWNPmUnczU8FoF8cGB',
to: AccountAddress.fromBase58(
'3ybJ66spZ2xdWF3avgxQb2meouYa7mpvMWNPmUnczU8FoF8cGB'
),
from: TEST_ACCOUNT,
tokenAmount: 100n,
}
Expand Down Expand Up @@ -207,16 +213,19 @@ describe('createTransfer', () => {
const { parameter, schema } = cis2.createTransfer({ energy: 10000n }, [
{
tokenId: '',
to: '3ybJ66spZ2xdWF3avgxQb2meouYa7mpvMWNPmUnczU8FoF8cGB',
to: AccountAddress.fromBase58(
'3ybJ66spZ2xdWF3avgxQb2meouYa7mpvMWNPmUnczU8FoF8cGB'
),
from: TEST_ACCOUNT,
tokenAmount: 100n,
},
{
tokenId: '',
from: TEST_ACCOUNT,
to: {
address: { index: 4416n, subindex: 0n },
hookName: 'onReceivingCIS2',
address: ContractAddress.create(4416),
hookName:
EntrypointName.fromStringUnchecked('onReceivingCIS2'),
},
tokenAmount: 0n,
},
Expand Down Expand Up @@ -261,7 +270,9 @@ test('dryRun.updateOperator', async () => {
TEST_ACCOUNT,
{
type: 'add',
address: '3ybJ66spZ2xdWF3avgxQb2meouYa7mpvMWNPmUnczU8FoF8cGB',
address: AccountAddress.fromBase58(
'3ybJ66spZ2xdWF3avgxQb2meouYa7mpvMWNPmUnczU8FoF8cGB'
),
},
TEST_BLOCK
);
Expand All @@ -278,11 +289,13 @@ test('dryRun.updateOperator', async () => {
[
{
type: 'add',
address: '3ybJ66spZ2xdWF3avgxQb2meouYa7mpvMWNPmUnczU8FoF8cGB',
address: AccountAddress.fromBase58(
'3ybJ66spZ2xdWF3avgxQb2meouYa7mpvMWNPmUnczU8FoF8cGB'
),
},
{
type: 'remove',
address: { index: 3494n, subindex: 0n },
address: ContractAddress.create(3494),
},
],
TEST_BLOCK
Expand All @@ -304,7 +317,9 @@ describe('createUpdateOperator', () => {
{ energy: 1000000n },
{
type: 'add',
address: '3ybJ66spZ2xdWF3avgxQb2meouYa7mpvMWNPmUnczU8FoF8cGB',
address: AccountAddress.fromBase58(
'3ybJ66spZ2xdWF3avgxQb2meouYa7mpvMWNPmUnczU8FoF8cGB'
),
}
);

Expand Down Expand Up @@ -339,11 +354,13 @@ describe('createUpdateOperator', () => {
const { parameter } = cis2.createUpdateOperator({ energy: 1000000n }, [
{
type: 'add',
address: '3ybJ66spZ2xdWF3avgxQb2meouYa7mpvMWNPmUnczU8FoF8cGB',
address: AccountAddress.fromBase58(
'3ybJ66spZ2xdWF3avgxQb2meouYa7mpvMWNPmUnczU8FoF8cGB'
),
},
{
type: 'remove',
address: { index: 3494n, subindex: 0n },
address: ContractAddress.create(3494),
},
]);
const expectedParameterHex =
Expand Down
Loading

0 comments on commit 8545066

Please sign in to comment.