Skip to content

Commit

Permalink
Cleanup outdated FT/NFT related contract codes and tests
Browse files Browse the repository at this point in the history
  • Loading branch information
SupunS committed Oct 18, 2024
1 parent 0b1fc2b commit cf0472b
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 1,278 deletions.
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

0 comments on commit cf0472b

Please sign in to comment.