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

[TX] Add remaining platform tx to caminoExecutor (spend / lock) #21

Merged
merged 2 commits into from
Jan 10, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions e2e_tests/cchain_nomock.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,9 @@ describe("CChain", (): void => {
() => keystore.createUser(user, passwd),
(x) => x,
Matcher.toEqual,
() => { return {} }
() => {
return {}
}
],
[
"importKey",
Expand Down Expand Up @@ -70,4 +72,4 @@ describe("CChain", (): void => {
]

createTests(tests_spec)
})
})
7 changes: 4 additions & 3 deletions e2e_tests/e2etestlib.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ export const getAvalanche = (): Avalanche => {
const avalanche: Avalanche = new Avalanche(
process.env.CAMINOGO_IP,
parseInt(process.env.CAMINOGO_PORT),
'http',
"http",
12345
)
return avalanche
Expand All @@ -35,7 +35,9 @@ export const createTests = (tests_spec: any[]): void => {
expect(preprocess(await promise())).toEqual(expected())
}
if (matcher == Matcher.toContain) {
expect(preprocess(await promise())).toEqual(expect.arrayContaining(expected()))
expect(preprocess(await promise())).toEqual(
expect.arrayContaining(expected())
)
}
if (matcher == Matcher.toMatch) {
expect(preprocess(await promise())).toMatch(expected())
Expand All @@ -50,4 +52,3 @@ export const createTests = (tests_spec: any[]): void => {
})
}
}

2 changes: 1 addition & 1 deletion e2e_tests/health_nomock.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,4 @@ describe("Info", (): void => {
]

createTests(tests_spec)
})
})
2 changes: 1 addition & 1 deletion e2e_tests/info_nomock.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -69,4 +69,4 @@ describe("Info", (): void => {
]

createTests(tests_spec)
})
})
26 changes: 19 additions & 7 deletions e2e_tests/keystore_nomock.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,9 @@ describe("Keystore", (): void => {
() => keystore.createUser(username1, password),
(x) => x,
Matcher.toEqual,
() => { return {} }
() => {
return {}
}
],
[
"createRepeatedUser",
Expand Down Expand Up @@ -62,7 +64,9 @@ describe("Keystore", (): void => {
() => keystore.importUser(username2, exportedUser.value, password),
(x) => x,
Matcher.toEqual,
() => { return {} }
() => {
return {}
}
],
[
"exportImportUser",
Expand All @@ -73,7 +77,9 @@ describe("Keystore", (): void => {
})(),
(x) => x,
Matcher.toEqual,
() => { return {} }
() => {
return {}
}
],
[
"listUsers2",
Expand All @@ -87,23 +93,29 @@ describe("Keystore", (): void => {
() => keystore.deleteUser(username1, password),
(x) => x,
Matcher.toEqual,
() => { return {} }
() => {
return {}
}
],
[
"deleteUser2",
() => keystore.deleteUser(username2, password),
(x) => x,
Matcher.toEqual,
() => { return {} }
() => {
return {}
}
],
[
"deleteUser3",
() => keystore.deleteUser(username3, password),
(x) => x,
Matcher.toEqual,
() => { return {} }
() => {
return {}
}
]
]

createTests(tests_spec)
})
})
11 changes: 6 additions & 5 deletions e2e_tests/pchain_nomock.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,7 @@ describe("PChain", (): void => {
const nodeID: string = "NodeID-AK7sPBsZM9rQwse23aLhEEBPHZD5gkLrL"
const subnetID: string = "2bGsYJorY6X7RhjPBFs3kYjiNEHo4zGrD2eeyZbb43T2KKi7fM"
const xChainAddr: string = "X-custom18jma8ppw3nhx5r4ap8clazz0dps7rv5u9xde7p"
const avalancheBlockChainID: string =
"11111111111111111111111111111111LpoYY"
const avalancheBlockChainID: string = "11111111111111111111111111111111LpoYY"

const rewardUTXOTxID: string =
"2nmH8LithVbdjaXsxVQCQfXtzN9hBbmebrsaEYnLM9T32Uy2Y4"
Expand All @@ -40,7 +39,9 @@ describe("PChain", (): void => {
() => keystore.createUser(user, passwd),
(x) => x,
Matcher.toEqual,
() => { return {} }
() => {
return {}
}
],
[
"createaddrB",
Expand Down Expand Up @@ -81,7 +82,7 @@ describe("PChain", (): void => {
],
[
"getBalanceOfMultipleAddresses",
() => pchain.getBalance({ addresses: [ whaleAddr ] }),
() => pchain.getBalance({ addresses: [whaleAddr] }),
(x) => x.balance,
Matcher.toBe,
() => "30000000000000000"
Expand Down Expand Up @@ -273,4 +274,4 @@ describe("PChain", (): void => {
]

createTests(tests_spec)
})
})
19 changes: 12 additions & 7 deletions e2e_tests/xchain_nomock.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,9 @@ describe("XChain", (): void => {
() => keystore.createUser(user, passwd),
(x) => x,
Matcher.toEqual,
() => { return {} }
() => {
return {}
}
],
[
"createaddrB",
Expand Down Expand Up @@ -59,7 +61,8 @@ describe("XChain", (): void => {
),
(x) => x,
Matcher.toThrow,
() => `problem retrieving user "${badUser}": incorrect password for user "${badUser}"`
() =>
`problem retrieving user "${badUser}": incorrect password for user "${badUser}"`
],
[
"incorrectPass",
Expand All @@ -76,7 +79,8 @@ describe("XChain", (): void => {
),
(x) => x,
Matcher.toThrow,
() => `problem retrieving user "${user}": incorrect password for user "${user}"`
() =>
`problem retrieving user "${user}": incorrect password for user "${user}"`
],
[
"getBalance",
Expand Down Expand Up @@ -159,8 +163,8 @@ describe("XChain", (): void => {
"AVAX"
),
(x) => x,
Matcher.toThrow,
() => "couldn't unmarshal an argument"
Matcher.Get,
() => tx
],
[
"import",
Expand Down Expand Up @@ -195,7 +199,8 @@ describe("XChain", (): void => {
xchain.mint(user, passwd, 1500, asset.value, addrB.value, [whaleAddr]),
(x) => x,
Matcher.toThrow,
() => "couldn't unmarshal an argument"
() =>
"provided addresses don't have the authority to mint the provided asset"
],
[
"getTx",
Expand All @@ -221,4 +226,4 @@ describe("XChain", (): void => {
]

createTests(tests_spec)
})
})
6 changes: 4 additions & 2 deletions examples/avm/buildExportTx-cchain-ant.ts
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,8 @@ const main = async (): Promise<any> => {
)
const utxoSet: UTXOSet = avmUTXOResponse.utxos
const amount: BN = new BN(350)
const threshold: number = 1
const toThreshold: number = 1
const changeThreshold: number = 1
const assetID: string = "Ycg5QzddNwe3ebfFXhoGUDnWgC6GE88QRakRnn9dp3nGwqCwD"

const unsignedTx: UnsignedTx = await xchain.buildExportTx(
Expand All @@ -86,7 +87,8 @@ const main = async (): Promise<any> => {
memo,
asOf,
locktime,
threshold,
toThreshold,
changeThreshold,
assetID
)

Expand Down
2 changes: 0 additions & 2 deletions examples/platformvm/baseTx-avax-create-multisig.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,6 @@ let pAddresses: Buffer[]
let pAddressStrings: string[]
let avaxAssetID: string
let fee: BN
let pChainBlockchainID: string
let avaxAssetIDBuf: Buffer
let xBlockchainID: string
let xBlockchainIDBuf: Buffer
Expand All @@ -71,7 +70,6 @@ const InitAvalanche = async () => {
pAddressStrings = pchain.keyChain().getAddressStrings()
avaxAssetID = avalanche.getNetwork().X.avaxAssetID
fee = pchain.getDefaultTxFee()
pChainBlockchainID = avalanche.getNetwork().P.blockchainID
avaxAssetIDBuf = bintools.cb58Decode(avaxAssetID)
xBlockchainID = avalanche.getNetwork().X.blockchainID
xBlockchainIDBuf = bintools.cb58Decode(xBlockchainID)
Expand Down
10 changes: 1 addition & 9 deletions examples/platformvm/buildAddDelegatorTx.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,29 +27,21 @@ const locktime: BN = new BN(0)
const memo: Buffer = Buffer.from(
"PlatformVM utility method buildAddDelegatorTx to add a delegator to the primary subnet"
)
const asOf: BN = UnixNow()
const asOf: BN = new BN(0)
const nodeID: string = "NodeID-DueWyGi3B9jtKfa9mPoecd4YSDJ1ftF69"
const startTime: BN = UnixNow().add(new BN(60 * 1))
const endTime: BN = startTime.add(new BN(2630000))

let pchain: PlatformVMAPI
let pKeychain: KeyChain
let pAddresses: Buffer[]
let pAddressStrings: string[]
let avaxAssetID: string
let fee: BN
let pChainBlockchainID: string

const InitAvalanche = async () => {
await avalanche.fetchNetworkSettings()
pchain = avalanche.PChain()
pKeychain = pchain.keyChain()
pKeychain.importKey(privKey)
pAddresses = pchain.keyChain().getAddresses()
pAddressStrings = pchain.keyChain().getAddressStrings()
avaxAssetID = avalanche.getNetwork().X.avaxAssetID
fee = pchain.getDefaultTxFee()
pChainBlockchainID = avalanche.getNetwork().P.blockchainID
}

const main = async (): Promise<any> => {
Expand Down
14 changes: 2 additions & 12 deletions examples/platformvm/buildAddSubnetValidatorTx.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,7 @@ import {
import { GetUTXOsResponse } from "@c4tplatform/caminojs/dist/apis/platformvm/interfaces"
import {
PrivateKeyPrefix,
DefaultLocalGenesisPrivateKey,
UnixNow
DefaultLocalGenesisPrivateKey
} from "@c4tplatform/caminojs/dist/utils"
import { ExamplesConfig } from "../common/examplesConfig"

Expand All @@ -26,16 +25,11 @@ let privKey: string = `${PrivateKeyPrefix}${DefaultLocalGenesisPrivateKey}`
const nodeID: string = "NodeID-NFBbbJ4qCmNaCzeW7sxErhvWqvEQMnYcN"
const startTime: BN = new BN(1652217329)
const endTime: BN = new BN(1653511017)
const asOf: BN = UnixNow()
const asOf: BN = new BN(0)

let pchain: PlatformVMAPI
let pKeychain: KeyChain
let pAddresses: Buffer[]
let pAddressStrings: string[]
let avaxAssetID: string
let fee: BN
let pChainBlockchainID: string
let avaxAssetIDBuf: Buffer

const InitAvalanche = async () => {
await avalanche.fetchNetworkSettings()
Expand All @@ -54,11 +48,7 @@ const InitAvalanche = async () => {
pKeychain.importKey(
"PrivateKey-2uWuEQbY5t7NPzgqzDrXSgGPhi3uyKj2FeAvPUHYo6CmENHJfn"
)
pAddresses = pchain.keyChain().getAddresses()
pAddressStrings = pchain.keyChain().getAddressStrings()
avaxAssetID = avalanche.getNetwork().X.avaxAssetID
fee = pchain.getDefaultTxFee()
pChainBlockchainID = avalanche.getNetwork().P.blockchainID
}

const main = async (): Promise<any> => {
Expand Down
12 changes: 1 addition & 11 deletions examples/platformvm/buildAddValidatorTx.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,30 +27,21 @@ const locktime: BN = new BN(0)
const memo: Buffer = Buffer.from(
"PlatformVM utility method buildAddValidatorTx to add a validator to the primary subnet"
)
const asOf: BN = UnixNow()
const nodeID: string = "NodeID-D1LbWvUf9iaeEyUbTYYtYq4b7GaYR5tnJ"
const startTime: BN = UnixNow().add(new BN(60 * 1))
const endTime: BN = startTime.add(new BN(26300000))
const delegationFee: number = 10

let pchain: PlatformVMAPI
let pKeychain: KeyChain
let pAddresses: Buffer[]
let pAddressStrings: string[]
let avaxAssetID: string
let fee: BN
let pChainBlockchainID: string

const InitAvalanche = async () => {
await avalanche.fetchNetworkSettings()
pchain = avalanche.PChain()
pKeychain = pchain.keyChain()
pKeychain.importKey(privKey)
pAddresses = pchain.keyChain().getAddresses()
pAddressStrings = pchain.keyChain().getAddressStrings()
avaxAssetID = avalanche.getNetwork().X.avaxAssetID
fee = pchain.getDefaultTxFee()
pChainBlockchainID = avalanche.getNetwork().P.blockchainID
}

const main = async (): Promise<any> => {
Expand All @@ -73,8 +64,7 @@ const main = async (): Promise<any> => {
delegationFee,
locktime,
threshold,
memo,
asOf
memo
)

const tx: Tx = unsignedTx.sign(pKeychain)
Expand Down
Loading