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

Cleanup outdated FT/NFT related contract codes and tests #3630

Merged
merged 1 commit into from
Oct 18, 2024
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
24 changes: 22 additions & 2 deletions ast/inspector_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,17 +25,37 @@ import (

"github.com/onflow/cadence/ast"
"github.com/onflow/cadence/parser"
"github.com/onflow/cadence/tests/examples"
)

// TestInspector_Elements compares Inspector against Inspect.
func TestInspector_Elements(t *testing.T) {

t.Parallel()

const code = `
access(all) contract interface FungibleToken {

access(all) resource interface Provider {
access(all) fun withdraw(amount: Int): @Vault
}

access(all) resource interface Receiver {
access(all) fun deposit(vault: @Vault)
}

access(all) resource interface Vault: Provider, Receiver {
access(all) balance: Int
}

access(all) fun absorb(vault: @Vault)

access(all) fun sprout(balance: Int): @Vault
}
`

program, err := parser.ParseProgram(
nil,
[]byte(examples.FungibleTokenContractInterface),
[]byte(code),
parser.Config{},
)
require.NoError(t, err)
Expand Down
126 changes: 0 additions & 126 deletions tests/checker/interface_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,7 @@ import (

"github.com/onflow/cadence/common"
"github.com/onflow/cadence/errors"
"github.com/onflow/cadence/parser"
"github.com/onflow/cadence/sema"
"github.com/onflow/cadence/stdlib"
"github.com/onflow/cadence/tests/examples"
. "github.com/onflow/cadence/tests/utils"
)

func constructorArguments(compositeKind common.CompositeKind) string {
Expand Down Expand Up @@ -1630,128 +1626,6 @@ func TestCheckInvalidTypeRequirementDeclaration(t *testing.T) {
})
}

// TODO: re-enable this test with the v2 fungible token contract
/* func TestCheckContractInterfaceFungibleToken(t *testing.T) {

t.Parallel()

const code = examples.FungibleTokenContractInterface

_, err := ParseAndCheck(t, code)
require.NoError(t, err)
} */

// TODO: re-enable this test with the v2 fungible token contract
/* func TestCheckContractInterfaceFungibleTokenConformance(t *testing.T) {

t.Parallel()

code := examples.FungibleTokenContractInterface + "\n" + examples.ExampleFungibleTokenContract

_, err := ParseAndCheckWithPanic(t, code)
require.NoError(t, err)
} */

func BenchmarkContractInterfaceFungibleToken(b *testing.B) {

const code = examples.FungibleTokenContractInterface

program, err := parser.ParseProgram(nil, []byte(code), parser.Config{})
if err != nil {
b.Fatal(err)
}

b.ReportAllocs()
b.ResetTimer()

for i := 0; i < b.N; i++ {
checker, err := sema.NewChecker(
program,
TestLocation,
nil,
&sema.Config{
AccessCheckMode: sema.AccessCheckModeNotSpecifiedUnrestricted,
},
)
if err != nil {
b.Fatal(err)
}
err = checker.Check()
if err != nil {
b.Fatal(err)
}
}
}

func BenchmarkCheckContractInterfaceFungibleTokenConformance(b *testing.B) {

code := examples.FungibleTokenContractInterface + "\n" + examples.ExampleFungibleTokenContract

program, err := parser.ParseProgram(nil, []byte(code), parser.Config{})
if err != nil {
b.Fatal(err)
}

baseValueActivation := sema.NewVariableActivation(sema.BaseValueActivation)
baseValueActivation.DeclareValue(stdlib.PanicFunction)

config := &sema.Config{
AccessCheckMode: sema.AccessCheckModeNotSpecifiedUnrestricted,
BaseValueActivationHandler: func(_ common.Location) *sema.VariableActivation {
return baseValueActivation
},
}

b.ReportAllocs()
b.ResetTimer()

for i := 0; i < b.N; i++ {
checker, err := sema.NewChecker(
program,
TestLocation,
nil,
config,
)
if err != nil {
b.Fatal(err)
}
err = checker.Check()
if err != nil {
b.Fatal(err)
}
}
}

// TODO: re-enable this test with the v2 fungible token contract
/* func TestCheckContractInterfaceFungibleTokenUse(t *testing.T) {

t.Parallel()

code := examples.FungibleTokenContractInterface + "\n" +
examples.ExampleFungibleTokenContract + "\n" + `

fun test(): Int {
let publisher <- ExampleToken.sprout(balance: 100)
let receiver <- ExampleToken.sprout(balance: 0)

let withdrawn <- publisher.withdraw(amount: 60)
receiver.deposit(vault: <-withdrawn)

let publisherBalance = publisher.balance
let receiverBalance = receiver.balance

destroy publisher
destroy receiver

return receiverBalance
}
`

_, err := ParseAndCheckWithPanic(t, code)

require.NoError(t, err)
} */

// TestCheckInvalidInterfaceUseAsTypeSuggestion tests that an interface
// can not be used as a type, and the suggestion to fix it is correct
func TestCheckInvalidInterfaceUseAsTypeSuggestion(t *testing.T) {
Expand Down
Loading
Loading