Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[ts-sdk] Allow enums with no value, add a test for TransactionData BCS #1484

Merged
merged 20 commits into from
Apr 21, 2022

Conversation

damirka
Copy link
Contributor

@damirka damirka commented Apr 20, 2022

Although API is pretty straightforward, I suggest first deal with this one and then build a handy abstraction layer above.

  • TransactionData for Transfer serializes and deserializes correctly with one exception: addresses are encoded as Vec<u8> on the Rust side, so technically they cannot be considered addresses in BCS. But ObjectID is encoded as address.

@damirka damirka added the javascript Pull requests that update Javascript code label Apr 20, 2022
@damirka damirka requested review from bmwill, stella3d and 666lcz April 20, 2022 10:54
@damirka damirka self-assigned this Apr 20, 2022
@damirka damirka requested a review from Clay-Mysten as a code owner April 20, 2022 10:54
Copy link
Contributor

@stella3d stella3d left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

looks good!
left a few questions to clarify details, and suggested a test format change, but this could be merged as-is

throw new Error(`Type ${elementType} is not registered`);
}
): typeof BCS {
// OMITTING SAFETY CHECK TO ALLOW RECURSIVE DEFINITIONS
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

how important is this warning ? should we be worried about future issues or is it probably fine?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is a temporary solution, we'll see if we need to provide safety guarantees at early stages or later on. It unblocks having Type { val: Option<Type> }, which is good and allowed by BCS standard.

@@ -3,13 +3,12 @@

import { BCS } from '../../src/bcs';
import { Base64DataBuffer as B64 } from '../../src';
// import { HexDataBuffer as HEX } from '../../src';
import { BN } from 'bn.js';
import * as BN from 'bn.js';
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: i didn't see anything else being used from BN, we could make this import more specific to avoid having to do new BN.BN(1)

@@ -108,12 +107,122 @@ describe('Move BCS', () => {
expect(data.kitties).toHaveLength(2);
expect(data.owner).toEqual('00000000000000000000000000c0ffee');
});

it('should de/ser TransactionData::Transfer', () => {
registerSuiCoreTypes(BCS);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

when writing multiple tests with a common setup step, i think it's helpful to abstract out that step into its own setup function. This helps the tests to stay easy to read and write

here, that would look like:

describe('TransactionData', () => {
    beforeEach(() => {
        registerSuiCoreTypes(BCS);
    });
    
    it('should de/ser Self::Transfer', () => {
       // same test but with the register types line removed
    });
    
    // other tests with same change
});

@damirka damirka merged commit 84fedaa into main Apr 21, 2022
@damirka damirka deleted the ds/move-bcs branch April 21, 2022 12:28
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
javascript Pull requests that update Javascript code
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants