-
Notifications
You must be signed in to change notification settings - Fork 40
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #344 from coinbase/marcin/validator-details
Add extra support for more getters for the Validator class
- Loading branch information
Showing
3 changed files
with
213 additions
and
1 deletion.
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,95 @@ | ||
import { Validator } from "../coinbase/validator"; | ||
import { ValidatorStatus } from "../coinbase/types"; | ||
import { Validator as ValidatorModel } from "../client"; | ||
import { Coinbase } from "../coinbase/coinbase"; | ||
import { ValidatorStatus as APIValidatorStatus } from "../client/api"; | ||
|
||
describe("Validator", () => { | ||
let validator: Validator; | ||
|
||
beforeEach(() => { | ||
const mockModel: ValidatorModel = { | ||
validator_id: "123", | ||
status: APIValidatorStatus.Active, | ||
network_id: Coinbase.networks.EthereumHolesky, | ||
asset_id: Coinbase.assets.Eth, | ||
details: { | ||
effective_balance: { | ||
amount: "100", | ||
asset: { network_id: Coinbase.networks.EthereumHolesky, asset_id: Coinbase.assets.Eth }, | ||
}, | ||
balance: { | ||
amount: "200", | ||
asset: { network_id: Coinbase.networks.EthereumHolesky, asset_id: Coinbase.assets.Eth }, | ||
}, | ||
exitEpoch: "epoch-1", | ||
activationEpoch: "epoch-0", | ||
index: "0", | ||
public_key: "public-key-123", | ||
slashed: false, | ||
withdrawableEpoch: "epoch-2", | ||
withdrawal_address: "withdrawal-address-123", | ||
}, | ||
}; | ||
|
||
validator = new Validator(mockModel); | ||
}); | ||
|
||
test("getValidatorId should return the correct validator ID", () => { | ||
expect(validator.getValidatorId()).toBe("123"); | ||
}); | ||
|
||
test("getStatus should return the correct status", () => { | ||
expect(validator.getStatus()).toBe(ValidatorStatus.ACTIVE); | ||
}); | ||
|
||
test("getNetworkId should return the correct network ID", () => { | ||
expect(validator.getNetworkId()).toBe(Coinbase.networks.EthereumHolesky); | ||
}); | ||
|
||
test("getAssetId should return the correct asset ID", () => { | ||
expect(validator.getAssetId()).toBe(Coinbase.assets.Eth); | ||
}); | ||
|
||
test("getActivationEpoch should return the correct activation epoch", () => { | ||
expect(validator.getActivationEpoch()).toBe("epoch-0"); | ||
}); | ||
|
||
test("getExitEpoch should return the correct exit epoch", () => { | ||
expect(validator.getExitEpoch()).toBe("epoch-1"); | ||
}); | ||
|
||
test("getIndex should return the correct index", () => { | ||
expect(validator.getIndex()).toBe("0"); | ||
}); | ||
|
||
test("getPublicKey should return the correct public key", () => { | ||
expect(validator.getPublicKey()).toBe("public-key-123"); | ||
}); | ||
|
||
test("isSlashed should return the correct slashed status", () => { | ||
expect(validator.isSlashed()).toBe(false); | ||
}); | ||
|
||
test("getWithdrawableEpoch should return the correct withdrawable epoch", () => { | ||
expect(validator.getWithdrawableEpoch()).toBe("epoch-2"); | ||
}); | ||
|
||
test("getWithdrawalAddress should return the correct withdrawal address", () => { | ||
expect(validator.getWithdrawalAddress()).toBe("withdrawal-address-123"); | ||
}); | ||
|
||
test("getEffectiveBalance should return the correct effective balance", () => { | ||
expect(validator.getEffectiveBalance()).toEqual({ | ||
amount: "100", | ||
asset: { network_id: Coinbase.networks.EthereumHolesky, asset_id: Coinbase.assets.Eth }, | ||
}); | ||
}); | ||
|
||
test("getBalance should return the correct balance", () => { | ||
expect(validator.getBalance()).toEqual({ | ||
amount: "200", | ||
asset: { network_id: Coinbase.networks.EthereumHolesky, asset_id: Coinbase.assets.Eth }, | ||
}); | ||
}); | ||
}); |