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

test: Audit some integration tests, make minor changes, and add plaintext test list #2089

Open
wants to merge 82 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 60 commits
Commits
Show all changes
82 commits
Select commit Hold shift + click to select a range
661e907
Add script to summarize integration tests
p-offtermatt Jul 23, 2024
30f0c57
Add error messages for missing docstrings
p-offtermatt Jul 23, 2024
a546d83
Use better separator
p-offtermatt Jul 23, 2024
ae2f994
Add docstring to test
p-offtermatt Jul 23, 2024
0a0d95f
Add some docstrings and adjust formatting
p-offtermatt Jul 23, 2024
ca5351a
Add some more docstrings
p-offtermatt Jul 23, 2024
1e51a5d
Add makefile and git workflow
p-offtermatt Jul 23, 2024
d13e029
Add else case
p-offtermatt Jul 23, 2024
42cb502
Use temporary files instead of substitution
p-offtermatt Jul 23, 2024
c6587bf
Add missing fi
p-offtermatt Jul 23, 2024
24012c1
Adding a docstring without regenerating the test docs
p-offtermatt Jul 23, 2024
1203d5c
Give testing-docs workflow write permission
p-offtermatt Jul 23, 2024
87dbfa1
Specify branch to push to
p-offtermatt Jul 23, 2024
82f6dcb
Just fail the test instead of pushing automatically
p-offtermatt Jul 23, 2024
e6e872d
Regenerate testing docs
p-offtermatt Jul 23, 2024
72c62c5
Rename workflow
p-offtermatt Jul 23, 2024
99ee1a2
Unify type imports
p-offtermatt Jul 23, 2024
e2eed4e
Add newline around fenced codeblock
p-offtermatt Jul 23, 2024
dfa64ca
Fix repeated 'or'
p-offtermatt Jul 23, 2024
398aa44
Regenerate testing doc
p-offtermatt Jul 23, 2024
0d54836
Expand docstring for TestAllocateTokens
p-offtermatt Jul 23, 2024
ff24042
Adjust testing docs workflow
p-offtermatt Jul 23, 2024
c26b75c
Improved some test descriptions
kirdatatjana Aug 23, 2024
4e11ae9
Improved misbehavior.go test descriptions
kirdatatjana Aug 23, 2024
ae10a12
Improved normal_operations.go test descriptions
kirdatatjana Aug 26, 2024
62a5181
Improved provider_gov_hooks.go test descriptions
kirdatatjana Aug 26, 2024
df4de45
Improved query_providerinfo_test.go test descriptions
kirdatatjana Aug 26, 2024
dbc0051
Removed warnings from setup.go
kirdatatjana Aug 26, 2024
bb00e27
Improved slashing.go test descriptions
kirdatatjana Aug 27, 2024
c193198
Improved stop_consumer.go test descriptions
kirdatatjana Aug 27, 2024
e3ebe8c
Improved throttle_retry.go test descriptions
kirdatatjana Aug 27, 2024
547ef24
Improved throttle.go test descriptions
kirdatatjana Aug 28, 2024
31a85e0
Fixed spelling mistake
kirdatatjana Aug 28, 2024
6707dcc
Improved valset_update.go test descriptions
kirdatatjana Aug 29, 2024
3e88448
Resolved conflicts
kirdatatjana Aug 29, 2024
d6af82e
Improved test documentation
kirdatatjana Aug 30, 2024
eec9559
Improved testing-docs.yml
kirdatatjana Aug 30, 2024
3d4e8b3
Testing git workflow for testing-docs
kirdatatjana Aug 30, 2024
ce18476
Testing git workflow for testing-docs
kirdatatjana Aug 30, 2024
9c16b64
Testing git workflow for testing-docs
kirdatatjana Aug 30, 2024
458a956
Testing git workflow for testing-docs
kirdatatjana Aug 30, 2024
7d0e31a
Testing git workflow for testing-docs
kirdatatjana Aug 30, 2024
48808df
Testing git workflow for testing-docs
kirdatatjana Aug 30, 2024
62279bf
Update testing documentation
invalid-email-address Aug 30, 2024
db65fbf
Testing git workflow for testing-docs
kirdatatjana Aug 30, 2024
464fa3b
Testing git workflow for testing-docs
kirdatatjana Aug 30, 2024
f9c5760
Update testing documentation
invalid-email-address Aug 30, 2024
b1ea0ee
Testing git workflow for testing-docs
kirdatatjana Aug 30, 2024
096afcd
Update testing documentation
invalid-email-address Aug 30, 2024
efc71c2
Improved some test descriptions
kirdatatjana Aug 30, 2024
833227c
Update testing documentation
invalid-email-address Aug 30, 2024
675aaef
Fix minor typos
kirdatatjana Aug 30, 2024
4088bbf
Merge remote-tracking branch 'origin/ph/test-table' into ph/test-table
kirdatatjana Aug 30, 2024
a45c6c9
Finished testing-docs.yml
kirdatatjana Aug 30, 2024
02b0a38
Fix minor typos
kirdatatjana Sep 2, 2024
cd346d0
Rename test from testing-docs.yml
kirdatatjana Sep 2, 2024
e52ae4e
Cleaned up TODOs and updated test descriptions
kirdatatjana Sep 4, 2024
281e226
Added check in misbehaviour.go
kirdatatjana Sep 5, 2024
72a263b
Resolved conflicts with main
kirdatatjana Sep 11, 2024
d35efea
Fixed integration tests
kirdatatjana Sep 11, 2024
316e735
Removed additional comments from key_assignment.go
kirdatatjana Sep 11, 2024
e908514
Merge branch 'main' into ph/test-table
kirdatatjana Sep 11, 2024
e684fcd
Merge branch 'main' into ph/test-table
kirdatatjana Sep 11, 2024
dd0aeca
Removed outdated file descriptions
kirdatatjana Sep 16, 2024
d1473e4
Update testing documentation
invalid-email-address Sep 16, 2024
641208e
Update .github/workflows/testing-docs.yml
kirdatatjana Sep 16, 2024
9d357b4
Update tests/integration/README.md
kirdatatjana Sep 16, 2024
cd3dd19
Removed TestRelayAndApplyDoubleSignPacket test from slashing.go
kirdatatjana Sep 16, 2024
1f23596
Update testing documentation
invalid-email-address Sep 16, 2024
9d85473
Update .github/workflows/testing-docs.yml
kirdatatjana Sep 16, 2024
a888ae6
Update scripts/test_doc/test_documentation.md
kirdatatjana Sep 17, 2024
96c2ac4
Update testing documentation
invalid-email-address Sep 17, 2024
43cfa7a
Integration test comments refactored
kirdatatjana Sep 17, 2024
aafabb7
Update testing documentation
invalid-email-address Sep 17, 2024
6025b56
Update .github/workflows/testing-docs.yml
kirdatatjana Sep 17, 2024
1cb3095
Changed inconsistent make command name
kirdatatjana Sep 18, 2024
5fd305f
Merge branch 'ph/test-table' of https://github.com/cosmos/interchain-…
kirdatatjana Sep 18, 2024
11d2d1f
Testing testing-docs script
kirdatatjana Sep 18, 2024
7c47913
Update testing documentation
invalid-email-address Sep 18, 2024
9ee3cd0
Testing testing-docs script
kirdatatjana Sep 18, 2024
255af89
Update testing documentation
invalid-email-address Sep 18, 2024
1526ef7
Changed inconsistent make command in TESTING.md
kirdatatjana Sep 18, 2024
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
69 changes: 69 additions & 0 deletions .github/workflows/testing-docs.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
name: Generate up-to-date testing docs
kirdatatjana marked this conversation as resolved.
Show resolved Hide resolved

on:
workflow_call:
pull_request:
merge_group:
push:
branches:
- main
- release/v*
- feat/*

permissions:
Copy link
Contributor

@bermuell bermuell Sep 23, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

pls also add a comment providing info why extended permissions are needed for PRs and content here.
Existing comment is just repeating the setting but not providing the info why it's needed.

contents: write
pull-requests: write # 'write' access to pull requests

jobs:
testing-docs:
runs-on: ubuntu-latest

steps:
- name: Checkout repository
uses: actions/checkout@v4

- uses: actions/setup-go@v5
with:
go-version: "1.22"
check-latest: true
cache: true
cache-dependency-path: go.sum
- uses: technote-space/get-diff-action@v6.1.2
id: git_diff
with:
PATTERNS: |
tests/integration/**/*.go
**/Makefile
Makefile

- name: Generate testing docs
kirdatatjana marked this conversation as resolved.
Show resolved Hide resolved
run: make testing-docs

- name: Check for changes
kirdatatjana marked this conversation as resolved.
Show resolved Hide resolved
id: check_changes
run: |
git show HEAD:scripts/test_doc/test_documentation.md > committed_file.md
cp scripts/test_doc/test_documentation.md generated_file.md
if ! diff -q generated_file.md committed_file.md; then
echo "Documentation for integration tests is out of date. Updating and pushing changes..."
cp generated_file.md scripts/test_doc/test_documentation.md
Comment on lines +47 to +51
Copy link
Contributor

@bermuell bermuell Sep 23, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why not just using git diff --exit-code to see if there are changes. no need to copy back and forth the file


if [ -n "$GITHUB_HEAD_REF" ]; then
branch=$GITHUB_HEAD_REF
else
branch=${GITHUB_REF#refs/heads/}
fi

git fetch origin $branch
git checkout $branch

cp generated_file.md scripts/test_doc/test_documentation.md
git config user.name "github-actions"
git config user.email "github-actions@github.com"
git add scripts/test_doc/test_documentation.md
git commit -m "Update testing documentation"

git push origin "$branch"

exit 1
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why exit 1?

fi
3 changes: 3 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -266,6 +266,9 @@ build-docs-deploy:
build-docs-local:
@cd docs && ./build_local.sh

testing-docs:
kirdatatjana marked this conversation as resolved.
Show resolved Hide resolved
@cd scripts/test_doc && go run extract_docstrings.go

###############################################################################
### Test Traces ###
###############################################################################
Expand Down
12 changes: 12 additions & 0 deletions TESTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,18 @@ Unit tests are useful for simple standalone functionality, and CRUD operations.

To run integration tests against your own consumer/provider implementations, use [instance_test.go](tests/integration/instance_test.go) as an example. All you'll need to do is make sure your applications implement the necessary interfaces defined in [interfaces.go](testutil/integration/interfaces.go), pattern match [specific_setup.go](testutil/ibc_testing/specific_setup.go), then pass in the appropriate types and parameters to the suite, as is done in `instance_test.go` for the dummy provider/consumer implementations.

A list of test scenarios covered by integration tests can be found in [scripts/test_doc/test_documentation.md](scripts/test_doc/test_documentation.md).
When adding an integration test, write a brief description as a docstring in the Golang code in this schema:

```go
p-offtermatt marked this conversation as resolved.
Show resolved Hide resolved
// This is a test that tests foo and bar.
// @Long Description@
// Here is a detailed description
// that goes into more detail and describes the scenario.
```

Then, run `make docs-test` to update the test documentation.

## Model-Based Tests (MBT)

[MBT](tests/mbt/) tests are similar to integration tests, but they compare the system state to an expected state generated from a formally verified specification written in Quint.
Expand Down
139 changes: 139 additions & 0 deletions scripts/test_doc/extract_docstrings.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,139 @@
package main

import (
"fmt"
"go/ast"
"go/parser"
"go/token"
"log"
"os"
"path/filepath"
"strings"
)

func main() {
// Define the directory to traverse and the output markdown file
dir := "../../tests/integration"
outputFile := "test_documentation.md"
Comment on lines +16 to +17
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

provide this as command line arguments to make the script more flexible


// Open the output file
out, err := os.Create(outputFile)
if err != nil {
log.Fatalf("Error creating output file: %v\n", err)
}
defer out.Close()

// Write the header for the markdown file
fmt.Fprintf(out, "# Test Documentation\n\n")

errorStatusCode := false

// Walk through the directory
err = filepath.Walk(dir, func(path string, info os.FileInfo, err error) error {
if err != nil {
return err
}

// Only process .go files
if !info.IsDir() && strings.HasSuffix(info.Name(), ".go") && !strings.HasSuffix(info.Name(), "_test.go") {
functionsMissingDocStrings := extractDocstrings(path, out)
if len(functionsMissingDocStrings) > 0 {
fmt.Printf("The following test functions in %s are missing docstrings:\n", path)
for _, fn := range functionsMissingDocStrings {
fmt.Printf("\t%s\n", fn)
}
errorStatusCode = true
}
}
return nil
})
if err != nil {
log.Fatalf("Error walking the path %q: %v\n", dir, err)
}

fmt.Printf("Documentation generated successfully in %s\n", outputFile)

if errorStatusCode {
os.Exit(1)
}
}

// extractDocstrings extracts the docstrings from the Go source file and writes them to the output file
// in a markdown table format.
// It returns a list of test functions that are missing docstrings.
func extractDocstrings(filePath string, out *os.File) []string {
// Read the Go source file
src, err := os.ReadFile(filePath)
if err != nil {
log.Fatalf("Error reading file %s: %v\n", filePath, err)
}

// Create the AST for the source file
fset := token.NewFileSet()
node, err := parser.ParseFile(fset, filePath, src, parser.ParseComments)
if err != nil {
log.Fatalf("Error parsing file %s: %v\n", filePath, err)
}

functionsMissingDocstrings := []string{}

// Files that do not contain test functions are excluded from the documentation.
fileNameWritten := false

// Traverse the AST
for _, f := range node.Decls {
if fn, isFn := f.(*ast.FuncDecl); isFn && strings.HasPrefix(fn.Name.Name, "Test") {
// Check if the function has a docstring
if fn.Doc != nil {

if !fileNameWritten {
relativePath := strings.TrimPrefix(filePath, "../../tests/integration/")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

too strong assumption from where the script is run? can this be made more generic?
especially needed when you consider to use test direcorty to be passed as cmd line argument

doclink := fmt.Sprintf("[%s](%s)", relativePath, filePath)
fmt.Fprintf(out, "# %s \n", doclink)
fmt.Fprintf(out, "<details><summary> Test Specifications </summary>\n\n")

// Write table header
fmt.Fprintf(out, "| Function | Short Description |\n")
fmt.Fprintf(out, "|----------|-------------------|\n")
fileNameWritten = true
}

doc := fn.Doc.Text()
link := fmt.Sprintf("[%s](%s#L%d)", fn.Name.Name, filePath, fset.Position(fn.Pos()).Line)

// Split the docstring based on the separator "========"
parts := strings.Split(doc, "\n@Long Description@\n")
var shortDescription, longDescription string
if len(parts) > 1 {
shortDescription = strings.TrimSpace(parts[0])
longDescription = strings.TrimSpace(parts[1])
} else {
shortDescription = strings.TrimSpace(doc)
longDescription = ""
}

// Format the description

// avoid breaking the table format: newlines need to be replaced
// for the short description, use spaces
shortDescription = strings.ReplaceAll(shortDescription, "\n", " ")
// for the long description, use breaks
longDescription = strings.ReplaceAll(longDescription, "\n", "<br>")

description := shortDescription
if longDescription != "" {
description += fmt.Sprintf("<details><summary>Details</summary>%s</details>", longDescription)
}

fmt.Fprintf(out, " %s | %s |\n", link, description)
} else {
functionsMissingDocstrings = append(functionsMissingDocstrings, fn.Name.Name)

}
}
}
if fileNameWritten {
fmt.Fprintf(out, "</details>\n\n")
}
return functionsMissingDocstrings
}
Loading
Loading