-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
small refactor and addition of epoch data source
- Loading branch information
Showing
9 changed files
with
161 additions
and
18 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,7 @@ | ||
clean: | ||
rm -rf vendor/ | ||
|
||
test: vendor | ||
test: | ||
TF_ACC=1 go test -v ./solana/... | ||
|
||
vendor: clean | ||
|
4 changes: 2 additions & 2 deletions
4
docs/data-sources/account_info.md → docs/data-sources/account.md
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,30 @@ | ||
--- | ||
# generated by https://github.com/hashicorp/terraform-plugin-docs | ||
page_title: "solana_epoch Data Source - terraform-provider-solana" | ||
subcategory: "" | ||
description: |- | ||
--- | ||
|
||
# solana_epoch (Data Source) | ||
|
||
|
||
|
||
|
||
|
||
<!-- schema generated by tfplugindocs --> | ||
## Schema | ||
|
||
### Optional | ||
|
||
- **id** (String) The ID of this resource. | ||
|
||
### Read-Only | ||
|
||
- **absolute_slot** (Number) The current absolute slot in the epoch | ||
- **block_height** (Number) The current block height | ||
- **epoch** (Number) The current epoch count | ||
- **slot_index** (Number) The current slot relative to the start of the current epoch | ||
- **slots_in_epoch** (Number) The number of slots in this epoch | ||
|
||
|
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,60 @@ | ||
package solana | ||
|
||
import ( | ||
"context" | ||
"fmt" | ||
|
||
"github.com/gagliardetto/solana-go/rpc" | ||
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" | ||
) | ||
|
||
func dataSourceEpoch() *schema.Resource { | ||
return &schema.Resource{ | ||
Read: dataSourceEpochRead, | ||
|
||
Schema: map[string]*schema.Schema{ | ||
"absolute_slot": { | ||
Type: schema.TypeInt, | ||
Description: "The current absolute slot in the epoch", | ||
Computed: true, | ||
}, | ||
"block_height": { | ||
Type: schema.TypeInt, | ||
Description: "The current block height", | ||
Computed: true, | ||
}, | ||
"epoch": { | ||
Type: schema.TypeInt, | ||
Description: "The current epoch count", | ||
Computed: true, | ||
}, | ||
"slot_index": { | ||
Type: schema.TypeInt, | ||
Description: "The current slot relative to the start of the current epoch", | ||
Computed: true, | ||
}, | ||
"slots_in_epoch": { | ||
Type: schema.TypeInt, | ||
Description: "The number of slots in this epoch", | ||
Computed: true, | ||
}, | ||
}, | ||
} | ||
} | ||
|
||
func dataSourceEpochRead(d *schema.ResourceData, meta interface{}) error { | ||
client := meta.(*providerConfig).rpcClient | ||
|
||
res, err := client.GetEpochInfo(context.Background(), rpc.CommitmentRecent) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
d.SetId(fmt.Sprintf("epoch:%d", uint64(res.Epoch))) | ||
d.Set("absolute_slot", uint64(res.AbsoluteSlot)) | ||
d.Set("block_height", uint64(res.TransactionCount)) | ||
d.Set("epoch", uint64(res.Epoch)) | ||
d.Set("slot_index", uint64(res.SlotIndex)) | ||
d.Set("slots_in_epoch", uint64(res.SlotsInEpoch)) | ||
return nil | ||
} |
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,48 @@ | ||
package solana | ||
|
||
import ( | ||
"fmt" | ||
"testing" | ||
|
||
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" | ||
"github.com/hashicorp/terraform-plugin-sdk/v2/terraform" | ||
) | ||
|
||
const ( | ||
testEpocDataConfig = ` | ||
provider "solana" { | ||
endpoint = "https://api.testnet.solana.com" | ||
} | ||
data "solana_epoch" "test" {} | ||
` | ||
) | ||
|
||
func TestAccEpocDataSource(t *testing.T) { | ||
resource.Test(t, resource.TestCase{ | ||
Providers: testAccProviders, | ||
Steps: []resource.TestStep{ | ||
{ | ||
Config: testEpocDataConfig, | ||
Check: resource.ComposeTestCheckFunc( | ||
testEpocDataSucceeds("data.solana_epoch.test"), | ||
), | ||
}, | ||
}, | ||
}) | ||
} | ||
|
||
func testEpocDataSucceeds(name string) resource.TestCheckFunc { | ||
return func(state *terraform.State) error { | ||
val, ok := state.RootModule().Resources[name] | ||
if !ok { | ||
return fmt.Errorf("Epoch Failure: %s not found", name) | ||
} | ||
|
||
if val.Primary.ID == "" { | ||
return fmt.Errorf("Epoch Failure: ID was not set") | ||
} | ||
|
||
return nil | ||
} | ||
} |
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