-
Notifications
You must be signed in to change notification settings - Fork 151
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
feat: add testing for plo endpoints #512
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Overall it looks good, but some minor grumbles
*/ | ||
const beingEnd = new BN(1000) as AbstractInt; | ||
const leasePeriodIndex = new BN(39) as AbstractInt; | ||
const vectorAuctions = typeFactory.vecOf([beingEnd, leasePeriodIndex]); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
auctions::AuctionInfo
is a Option<(LeasePeriodOf<T>, T::BlockNumber)>
so Option<[beginEnd, leasePeriodIndex]>
. I don't see the Option
part here. In the service we have it modelled as Option<Vec<AbstractInt>>
- should wrap this in an Option
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yea so this is actually wrapped in an Option inside of auctionInfoAt
, but there were two methods using vectorAuction's
so I didn't wrap it in an Option
in the outer scope. But you raised a good point with a previous comment typeFactory.optionOf(null)
so I fixed it all to be more on point, and now the variable are all inside of auctionInfoAt
and don't need to be in the outer scope anymore.
Inside of TypeFactory we now have a nullOf
, and that allows you too create a Null primitive type and pass it into Option. Good catch and great addition.
parasOptionsOne, | ||
parasOptionsTwo, | ||
]); | ||
const optionWinnings = typeFactory.optionOf(vectorWinnings); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should this be longer? like a length of 7 (Or whatever the SLOT_RANGE_COUNT
is)? The rest of the values can just be Option::None
, but I am concerned there could be behavior that relies on the length of auctions::Winning
.
It is defined as [Option<(<T as frame_system::Config>::AccountId, ParaId, BalanceOf<T>)>; SlotRange::SLOT_RANGE_COUNT]
where SLOT_RANGE_COUNT
is the length it will always be.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So I couldnt find where it says the minimum SLOT_RANGE_COUNT
is, but I know it's suppose to be a maximum of 10 per the older code about a week ago.
/// Total number of possible sub ranges of slots.
pub const SLOT_RANGE_COUNT: usize = 10;
This was the comment that they had for slot range.
Now the codes changed a bit which includes a generate_slot_range
macro.
/// * A constant
SLOT_RANGE_COUNT will count the total number of enum variants.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Lets hardcode it to 10 (I think we covered the rest in offline discussion.)
Co-authored-by: Zeke Mostov <32168567+emostov@users.noreply.github.com>
…rate-api-sidecar into tarik-plo-tests
@emostov I restructured the tests so that they all reflect 'user contract' tests. They all use |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM % nits
expect(sanitizeNumbers(response)).toMatchObject(expectedResponse); | ||
}); | ||
|
||
it('Should return the correct null values when auctionInfo is not of type Option', async () => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
it('Should return the correct null values when auctionInfo is not of type Option', async () => { | |
it('Should return the correct null values when auctionInfo is `None`', async () => { |
It should be of type Option
: Option::None
. In JSON though that gets converted into null
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The sanitizeNumber
specs are exhaustive for this stuff. See
substrate-api-sidecar/src/sanitize/sanitizeNumbers.spec.ts
Lines 572 to 575 in ae74ef7
it('converts None to null', () => { | |
const none = kusamaRegistry.createType('Option<Text>', null); | |
expect(sanitizeNumbers(none)).toBe(null); | |
}); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ahh gotcha, yea that makes sense. Empty Options are returned as null with sanitize numbers :)!
export const nullAuctionsInfoAt = (): Promise<Option<Null>> => | ||
Promise.resolve().then(() => { | ||
const nullPrimitive = typeFactory.nullOf(); | ||
const nullOption = typeFactory.optionOf(nullPrimitive); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you just pass in null
here instead of creating this more complicated polkadot-js null thing?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Well no is the simplest answer. The way its implemented to in polkadot/api is to create a emptyOption
method. Which is what I just added. It's definitely better than adding the nullOf
method as you mentioned.
public emptyOption = <T extends Codec>(typeName: keyof InterfaceTypes): Option<T> =>
new Option<T>(this.#registry, typeName);
And then we just add the Null primitive as the typeName
parasOptionsOne, | ||
parasOptionsTwo, | ||
]); | ||
const optionWinnings = typeFactory.optionOf(vectorWinnings); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Lets hardcode it to 10 (I think we covered the rest in offline discussion.)
…d proper data for winning in auctions
Added:
ParasService.crowdloansInfo
ParasService.crowdloans
ParasService.leaseInfo
ParasService.leasesCurrent
ParasService.paras
ParasService.auctionsCurrent