-
Notifications
You must be signed in to change notification settings - Fork 164
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add convertSubnetValidator tests and fix for passing
- Loading branch information
1 parent
e301e0b
commit c69e1e6
Showing
8 changed files
with
169 additions
and
59 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
import { pChainOwner, pChainOwnerBytes } from '../../../fixtures/pvm'; | ||
import { testSerialization } from '../../../fixtures/utils/serializable'; | ||
import { PChainOwner } from './pChainOwner'; | ||
|
||
testSerialization('PChainOwner', PChainOwner, pChainOwner, pChainOwnerBytes); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
import { concatBytes } from '@noble/hashes/utils'; | ||
import { toListStruct } from '../../../utils/serializeList'; | ||
import { pack, unpack } from '../../../utils/struct'; | ||
import { serializable } from '../../common/types'; | ||
import { Int } from '../../primitives'; | ||
import { Address } from '../common/address'; | ||
import { TypeSymbols } from '../../constants'; | ||
import type { Codec } from '../../codec'; | ||
|
||
/** | ||
* @see https://github.com/ava-labs/avalanchego/blob/master/vms/platformvm/warp/message/register_subnet_validator.go | ||
*/ | ||
@serializable() | ||
export class PChainOwner { | ||
_type = TypeSymbols.PChainOwner; | ||
|
||
constructor( | ||
public readonly threshold: Int, | ||
public readonly addresses: Address[], | ||
) {} | ||
|
||
getAddresses() { | ||
return this.addresses; | ||
} | ||
|
||
static fromBytes(bytes: Uint8Array, codec: Codec): [PChainOwner, Uint8Array] { | ||
const [threshold, addresses, remaining] = unpack( | ||
bytes, | ||
[Int, toListStruct(Address)], | ||
codec, | ||
); | ||
return [new PChainOwner(threshold, addresses), remaining]; | ||
} | ||
|
||
toBytes(codec: Codec) { | ||
return concatBytes(pack([this.threshold, this.addresses], codec)); | ||
} | ||
|
||
static fromNative(addresses: readonly Uint8Array[], threshold = 1) { | ||
return new PChainOwner( | ||
new Int(threshold), | ||
addresses.map((addr) => new Address(addr)), | ||
); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.